2x2x2 LED Cube

Embed Size (px)

Citation preview

  • 8/11/2019 2x2x2 LED Cube

    1/19

    2x2x2 LED Cube

    Smallest LED cubebringing up the Big concepts in Microcontroller Timing cycles.

    It consists of 8 LEDs being controlled through microcontroller to give amazing lighting Effects.

    A must try DIY project for beginners which can be extended to 4x4x4 or 8x8x8 and further, with 2x2x2

    cube as the basic building block.

    Components :

    {C} 8051 Microcontroller (AT89S52)- Itsa 40-pin microcontroller with 32 I/O lines. You can also use

    20-pin package (AT89S2051) with proper pin connections (refer datasheet).

    {C 8- LEDs (or More if some get burned while soldering) of any colour

    {C} NPN Transistors (BC547)

    {C Resistors- 1K, 220E

    {C}{ Other discrete components such as Crystal, Capacitors etc.

    {C} Some wires.

    Construction of the cube :

    The construction of LED cube is quite simple and easy to grasp.

    We have to construct two layers/rows of 4-LEDs in each. These two rows will then be connected together.

    Look at the figures below :

    http://www.engineersgarage.com/8051-microcontrollerhttp://www.engineersgarage.com/8051-microcontroller
  • 8/11/2019 2x2x2 LED Cube

    2/19

    Ads by Info

    Ads by Info

    It is clear that we have 6-control lines which will be responsible for the LED ON/OFF.

  • 8/11/2019 2x2x2 LED Cube

    3/19

    Out of these 6, Two lines i.e. Rows (R1,R2) are anodes(+).

    The columns are Cathodes(-).

    Working:To understand the working, let us consider that we want to ON an LED at position (C0,R1). For

    this we send a HIGH at R1 Terminal of cube through a transistor (A transistor is used because current

    through microcontroller is not sufficient to drive more than 1-2 LEDs) and a LOW at C0 terminal. This

    makes a complete path for the current and LED glows.

    Similarly we can control ON/OFF state of all LEDs individually or in a group of two/three/four,etc.

    Delaywill help us to create different patterns.

    Calculation of the pins required for cubes:

    {C}{ For 4x4x4 cube

    Rows-4 pins

    Columns- 4x4=16 pins{C For 8x8x8 cube

    Rows-8 pins

    Columns- 8x8=64 pins (however 64 pins are not there in low profile uC, so this can be done

    through Shift Registers)

    Similarly 16x16x16 and further can be constructed.

    Current consumption by LEDs :

    An important thing which must be kept in mind must be the current consumption by the LEDs.

    Below Chart clears this point :

  • 8/11/2019 2x2x2 LED Cube

    4/19

    Explanation of the code :

    In the declaration part, weveassociated Port-1 with rows and columns.

    Delay functions are declared and defined for different values.

    Functions for various patterns have been define under names such as p1(); p2(); p3();

    p2f(); etc.

    In the main() part these functions are being called one by one and hence a continuous

    pattern isGENERATED on the cube.

    Screen shots:

    http://www.engineersgarage.com/contribution/expert/2x2x2-led-cube-circuit-diagramhttp://www.engineersgarage.com/contribution/expert/2x2x2-led-cube-circuit-diagramhttp://www.engineersgarage.com/contribution/expert/2x2x2-led-cube-circuit-diagramhttp://www.engineersgarage.com/contribution/expert/2x2x2-led-cube-circuit-diagram
  • 8/11/2019 2x2x2 LED Cube

    5/19

  • 8/11/2019 2x2x2 LED Cube

    6/19

    Code :

  • 8/11/2019 2x2x2 LED Cube

    7/19

    #include

    sbit c0=P1^2; // Column 0

    sbit c1=P1^3; // Column 1

    sbit c2=P1^4; //Column 2

    sbit c3=P1^5; // Column 3

    sbit r2=P1^1; // Row 2

    sbit r1=P1^0; // Row 1

    void delay(int); // Delay function declaration (large delay)

    void delay1(int); // Delay function declaration (short delay)

    void p1(); //

    void p2(); //

    void p3(); //

    void p4(); // Functions for various patterns

    void p1f(); //

    void p2f(); //

    void p3f(); //

    void p4f(); //

    void main() // main()

    {

    while(1)

    {

    c0=c1=c3=c2=0;

    r1=r2=1;

    p1();

    p2();

    p3();

    p4();

    p1f();

    p2f();

    p3f();

    p2f();

    p1f();

    p4();

    p3();p2();

    p1();

    }

    }

  • 8/11/2019 2x2x2 LED Cube

    8/19

    void delay(int t) // delay definition

    {

    int i,j;

    for(i=0;i

  • 8/11/2019 2x2x2 LED Cube

    9/19

    delay1(8);

    c0=1; //

    c1=1;

    c2=0;

    c3=1;

    delay1(8); //c0=1;

    c1=1; //

    c2=1;

    c3=0;

    delay1(8);

    r1=r2=1; //pattrn 1 Repeat

    c0=0;

    c1=1;

    c2=1; //

    c3=1;

    delay1(8);

    c0=1;

    c1=0;

    c2=1;

    c3=1; //

    delay1(8);

    c0=1; //

    c1=1;

    c2=0;

    c3=1; //

    delay1(8);

    c0=1; //

    c1=1;c2=1;

    c3=0;

    delay1(8);

    r1=r2=1; // finishing of pattern 1

    c0=0;

    c1=1;

    c2=1;

    c3=1;

    delay1(8);

    }

    void p2()

    {

    r1=1; //pattern 2

    r2=0;

    c0=c1=0;

    c2=c3=1; //

    delay1(8);

  • 8/11/2019 2x2x2 LED Cube

    10/19

    r1=0;r2=1;

    c0=c1=0;

    c2=c3=1;

    delay1(8);

    r1=0;r2=1;c0=c1=1; //

    c2=c3=0;

    delay1(8);

    r1=1;

    r2=0;

    c0=c1=1;

    c2=c3=0;

    delay1(8); //

    r1=1; // pattern 2 repeat

    r2=0;

    c0=c1=0;

    c2=c3=1;

    delay1(8);

    r1=0;r2=1; //

    c0=c1=0;

    c2=c3=1;

    delay1(8);

    r1=0;r2=1;

    c0=c1=1; //c2=c3=0;

    delay1(8);

    r1=1;

    r2=0;

    c0=c1=1;

    c2=c3=0;

    delay1(8);

    r1=1; //pattern 2 repeating

    r2=0;c0=c1=0;

    c2=c3=1;

    delay1(8);

    r1=0;r2=1;

    c0=c1=0;

    c2=c3=1; //

    delay1(8);

  • 8/11/2019 2x2x2 LED Cube

    11/19

    r1=0;r2=1;

    c0=c1=1;

    c2=c3=0;

    delay1(8); //

    r1=1;

    r2=0;

    c0=c1=1; //

    c2=c3=0;

    delay1(8);

    r1=1; // pattern 2 repeat

    r2=0;

    c0=c1=0;

    c2=c3=1;

    delay1(8);

    r1=0;r2=1; //

    c0=c1=0;

    c2=c3=1;

    delay1(8);

    r1=0;r2=1;

    c0=c1=1;

    c2=c3=0;

    delay1(8);

    //

    r1=1;r2=0;

    c0=c1=1;

    c2=c3=0;

    delay1(8);

    r1=1; // finishing of patt. 2

    r2=0;

    c0=c1=0;

    c2=c3=1;

    delay1(8);

    }

    void p3()

    {

    r1=1;r2=0; // Pattern 3 repeat

    c0=0;c3=0;

    c1=c2=1;

    delay1(8);

    r2=1;r1=0;

  • 8/11/2019 2x2x2 LED Cube

    12/19

    c0=c3=0;

    c1=c2=1;

    delay1(8);

    c1=c2=0;

    c0=c3=1;delay(8);

    r1=1;r2=0;

    c1=c2=0;

    c0=c3=1;

    delay1(8);

    r1=1;r2=0; // Pattern 3 repeat

    c0=0;c3=0;

    c1=c2=1;

    delay1(8);

    r2=1;r1=0;

    c0=c3=0;

    c1=c2=1; //

    delay1(8);

    c1=c2=0;

    c0=c3=1;

    delay(8);

    r1=1;r2=0; //

    c1=c2=0;c0=c3=1;

    delay1(8);

    r1=1;r2=0; // repeat Pattern 3

    c0=0;c3=0;

    c1=c2=1;

    delay1(8);

    r2=1;r1=0;

    c0=c3=0;

    c1=c2=1;delay1(8);

    c1=c2=0;

    c0=c3=1;

    delay1(8);

    r1=1;r2=0;

    c1=c2=0;

  • 8/11/2019 2x2x2 LED Cube

    13/19

    c0=c3=1;

    delay1(8);

    r1=1;r2=0; // finishing Pattern 3

    c0=0;c3=0;

    c1=c2=1;delay1(8);

    }

    void p4()

    {

    r1=0;r2=1; //

    c0=0;c1=c3=c2=1;

    delay1(8);

    r2=0;r1=1;

    c1=0;c2=c0=c3=1; //

    delay1(8);

    r1=0;r2=1;

    c2=0;c1=c3=c0=1;

    delay1(8);

    //

    r2=0;r1=1;

    c3=0;c2=c0=c1=1;

    delay1(8);

    }

    void p1f()

    {

    r1=r2=1; //pattern 1 FAST

    c0=0;

    c1=1;

    c2=1;

    c3=1;

    delay(10);

    c0=1; //

    c1=0;c2=1;

    c3=1;

    delay(10);

    c0=1;

    c1=1;

    c2=0; //

    c3=1;

    delay(10);

  • 8/11/2019 2x2x2 LED Cube

    14/19

    c0=1;

    c1=1;

    c2=1;

    c3=0;

    delay(10);

    r1=r2=1; //pattrn 1 Repeat FAST

    c0=0;

    c1=1;

    c2=1;

    c3=1;

    delay(10);

    c0=1; //

    c1=0;

    c2=1;

    c3=1;

    delay(10);

    c0=1;

    c1=1;

    c2=0; //

    c3=1;

    delay(10);

    c0=1;

    c1=1;

    c2=1;

    c3=0;

    delay(10);

    r1=r2=1; //pattrn 1 Repeat

    c0=0;c1=1;

    c2=1;

    c3=1; //

    delay(10);

    c0=1;

    c1=0;

    c2=1;

    c3=1; //

    delay(10);

    c0=1;

    c1=1;c2=0;

    c3=1;

    delay(10); //

    c0=1;

    c1=1;

    c2=1;

    c3=0;

    delay(10);

  • 8/11/2019 2x2x2 LED Cube

    15/19

    r1=r2=1; // finishing of pattern 1

    c0=0;

    c1=1;

    c2=1;

    c3=1;delay(10);

    }

    void p2f()

    {

    r1=1; //pattern 2 FAST

    r2=0;

    c0=c1=0;

    c2=c3=1;

    delay(10);

    r1=0;r2=1;

    c0=c1=0;

    c2=c3=1;

    delay(10);

    r1=0;r2=1;

    c0=c1=1;

    c2=c3=0; //

    delay(10);

    r1=1;

    r2=0; //c0=c1=1;

    c2=c3=0;

    delay(10);

    r1=1; // pattern 2 repeat fast

    r2=0;

    c0=c1=0;

    c2=c3=1;

    delay(10);

    //

    r1=0;r2=1;c0=c1=0;

    c2=c3=1;

    delay(10);

    //

    r1=0;r2=1;

    c0=c1=1;

    c2=c3=0;

    delay(10);

  • 8/11/2019 2x2x2 LED Cube

    16/19

    r1=1; //

    r2=0;

    c0=c1=1;

    c2=c3=0;

    delay(10);

    r1=1; //pattern 2 repeat FAST

    r2=0;

    c0=c1=0;

    c2=c3=1;

    delay(10);

    //

    r1=0;r2=1;

    c0=c1=0;

    c2=c3=1;

    delay(10);

    r1=0;r2=1; //

    c0=c1=1;

    c2=c3=0;

    delay(10);

    r1=1;

    r2=0;

    c0=c1=1;

    c2=c3=0;

    delay(10);

    r1=1; // pattern 2 repeat FAST

    r2=0;

    c0=c1=0;

    c2=c3=1;

    delay(10);

    r1=0;r2=1;

    c0=c1=0;

    c2=c3=1;

    delay(10); //

    r1=0;r2=1;

    c0=c1=1;

    c2=c3=0;

    delay(10);

    r1=1;

    r2=0;

    c0=c1=1;

  • 8/11/2019 2x2x2 LED Cube

    17/19

    c2=c3=0;

    delay(10);

    r1=1; // finishing of patt. 2

    r2=0;

    c0=c1=0;

    c2=c3=1;delay(10);

    }

    void p3f()

    {

    r1=1;r2=0; // Pattern 3 FAST

    c0=0;c3=0;

    c1=c2=1;

    delay(10);

    r2=1;r1=0;

    c0=c3=0;

    c1=c2=1;

    delay(10);

    c1=c2=0;

    c0=c3=1;

    delay(10);

    r1=1;r2=0;

    c1=c2=0;

    c0=c3=1;

    delay(10);

    r1=1;r2=0; // repeat Pattern 3 FAST

    c0=0;c3=0;

    c1=c2=1;

    delay(10);

    r2=1;r1=0;

    c0=c3=0;

    c1=c2=1; //

    delay(10);

    c1=c2=0;c0=c3=1;

    delay(10);

    r1=1;r2=0;

    c1=c2=0;

    c0=c3=1;

    delay(10);

  • 8/11/2019 2x2x2 LED Cube

    18/19

    r1=1;r2=0; // Pattern 3 repeat FAST

    c0=0;c3=0;

    c1=c2=1; //

    delay(10);

    r2=1;r1=0;c0=c3=0;

    c1=c2=1;

    delay(10);

    c1=c2=0; //

    c0=c3=1;

    delay(10);

    r1=1;r2=0;

    c1=c2=0; //

    c0=c3=1;

    delay(10);

    r1=1;r2=0; // finishing Pattern 3

    c0=0;c3=0;

    c1=c2=1;

    delay(10);

    }

  • 8/11/2019 2x2x2 LED Cube

    19/19