Share My Creation 4X4X4 LED CUBE

Discussion in 'B4R Share Your Creations' started by Cableguy, May 16, 2016.

  1. Cableguy

    Cableguy Expert Licensed User

    Hi Guys....

    It gives me great pleasure to be the first sharing my creation with B4R!

    This is one of those "everyone builds this" kind of thing, and there are literally thousands of examples using Arduino to builds this, as well of other variations...

    This is my 4X4X4 LED CUBE

    Materials:

    64 Leds, I'm using white-bright 5mm ones
    20 connection cables
    1 Arduino compatible board with at least 20 I/O pins
    Patience... lots of it

    and of course, B4R IDE

    Obs...Most of the designs I found, use Transistors as a switch to enable each layer... But I found one designe that didn't use them, instead, it connected each layer wire to an analogic pin (A0-A5) and set it to 0, witch seems to simply connect it to GND.

    The CUBE construction is the thing that will take the longest and that is more prone to mistakes.
    Here a base representation of it:

    th.jpg

    I decided to build mine "freehanded" and thus not use any kind of positioning jig... This resulted in a "FrankenVersion" of this base wiring... Not pretty, but it works!

    Here's my CUBE:

    led2.jpg
    An this is the wirings (remember that I do not use those transistors) ....

    thU4FOA1IF.jpg


    So, each layer consists of 16 Leds, common ground.
    Each Ground (there are 4 of them) is connected to an Analogic pin (A0-A3) and the remaining 16 pins each go to a LED column.

    Here is my CUBE at work!


    Now, The B4R part....

    First I declared 2 global Arrays, One 4 in size, and the other 16 in size, These refer to each led in each layer...
    Then comes the dimming... Yes, 20 of them.
    Then its all a matter of turning on the leds in sequence... just for testing...

    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Private PinVcc(16As Pin 'Rows
        Private PinGnd(4As Pin 'Colloms
    End Sub

    Public Sub Initialize
        PinGnd(
    0).Initialize(PinGnd(0).A0, PinGnd(0).MODE_OUTPUT)
        PinGnd(
    1).Initialize(PinGnd(1).A1, PinGnd(1).MODE_outPUT)
        PinGnd(
    2).Initialize(PinGnd(2).A2, PinGnd(2).MODE_outPUT)
        PinGnd(
    3).Initialize(PinGnd(3).A3, PinGnd(3).MODE_outPUT)

        PinVcc(
    0).Initialize(PinVcc(0).A4, PinVcc(0).MODE_OUTPUT)
        PinVcc(
    1).Initialize(PinVcc(1).A5, PinVcc(1).MODE_OUTPUT)
        PinVcc(
    2).Initialize(0, PinVcc(2).MODE_OUTPUT)
        PinVcc(
    3).Initialize(1, PinVcc(3).MODE_OUTPUT)
        PinVcc(
    4).Initialize(2, PinVcc(4).MODE_OUTPUT)
        PinVcc(
    5).Initialize(3, PinVcc(5).MODE_OUTPUT)
        PinVcc(
    6).Initialize(4, PinVcc(6).MODE_OUTPUT)
        PinVcc(
    7).Initialize(5, PinVcc(7).MODE_OUTPUT)
        PinVcc(
    8).Initialize(6, PinVcc(8).MODE_OUTPUT)
        PinVcc(
    9).Initialize(7, PinVcc(9).MODE_OUTPUT)
        PinVcc(
    10).Initialize(8, PinVcc(10).MODE_OUTPUT)
        PinVcc(
    11).Initialize(9, PinVcc(11).MODE_OUTPUT)
        PinVcc(
    12).Initialize(10, PinVcc(12).MODE_OUTPUT)
        PinVcc(
    13).Initialize(11, PinVcc(13).MODE_OUTPUT)
        PinVcc(
    14).Initialize(12, PinVcc(14).MODE_OUTPUT)
        PinVcc(
    15).Initialize(13, PinVcc(15).MODE_OUTPUT)
       
        Reset   

    End Sub

    Public Sub Reset
        
    For n = 0 To 3
            PinGnd(n).DigitalWrite(
    True)
        
    Next
        
    For n = 0 To 15
            PinVcc(
    0).DigitalWrite(False)
        
    Next
    End Sub

    Public Sub TestLeds
        SequenceLeds
        Reset
        SequenceLayers
        Reset


    End Sub

    Private Sub SequenceLeds As Boolean
        
    For x = 0 To 3
            PinGnd(x).DigitalWrite(
    False)
            
    For n = 0 To 15
                PinVcc(n).DigitalWrite(
    True)
                Delay(
    100)
                PinVcc(n).DigitalWrite(
    False)   
            
    Next
            PinGnd(x).DigitalWrite(
    True)
        
    Next
        
    Return True
    End Sub

    private Sub SequenceLayers As Boolean
        
    For x = 0 To 3
            PinGnd(x).DigitalWrite(
    False)
            
    For n = 0 To 15
                PinVcc(n).DigitalWrite(
    True)   
            
    Next
            Delay(
    200)
            PinGnd(x).DigitalWrite(
    True)
        
    Next
        
    Return True
    End Sub

    Public Sub LED(n As Int, ON As Boolean)
        
    Dim row As Int = n/16
        
    Dim collomn As Int = ( n -( 16 * row ))
        
    If ON = True Then
            PinGnd(row).DigitalWrite(
    False)
            PinVcc(collomn).DigitalWrite(
    True)
        
    Else
            PinGnd(row).DigitalWrite(
    True)
            PinVcc(collomn).DigitalWrite(
    False)
        
    End If
    End Sub
    One note, since the TX/RX pins are also used to control leds, and I didn't eliminate the "serial.initialize(..." part, those leds are always in a variable ON state, reflecting the flow in TX/RX...

    This is still very far from being a finished "art piece", and its only purpose was to be the first in the share your creations forum!
    Maybe I will build a better and proper 8X8X8 RGB B4R controlled Cube in a near future...
     
    Last edited: May 16, 2016
  2. sorex

    sorex Expert Licensed User

    is there a video or video link missing here?
     
  3. Cableguy

    Cableguy Expert Licensed User

    The first post is now complete!
     
    Last edited: May 16, 2016
    Peter Simpson and Erel like this.
  4. wonder

    wonder Expert Licensed User

    Make it RGB (1204, 1204, 1204) and you'll have an HD-ish 3D "holographic" display. ;)

    You could even start your own business! I'd buy it!
     
    lemonisdead likes this.
  5. Cableguy

    Cableguy Expert Licensed User

    I don't think that could be done with Arduino....
    not that it isn't capable of controlling all those leds, using addressable rgb leds would make it easy, but to control the data flow, would be a pain!!!
    I do plan to start making things...
    I received my nano, and it really is ... nano!
     
    wonder likes this.
  6. JordiCP

    JordiCP Well-Known Member Licensed User

    Looks nice. Congrats!

    Is it a cat (on the top right) moving its tail when the cube leds are lighting? :D
     
    Cableguy likes this.
  7. Cableguy

    Cableguy Expert Licensed User

    indeed it is!
     
    Peter Simpson and JordiCP like this.
  8. Beja

    Beja Expert Licensed User

    Your very patient.
    Thanks for sharing.
     
  9. wonder

    wonder Expert Licensed User

    Can you add x, y, z functions?

    Code:
    'Switches an individual LED ON/OFF
    Sub LED_Switch(x As Int, y As Int, z As Int)
        
    'Something like this:
        LED(x, y, z).State = Not(LED(x, y, z).State)
    End Sub

    'Switches an individual LED ON
    Sub LED_On(x As Int, y As Int, z As Int)
        
    'Something like this:
        LED(x, y, z).State = True
    End Sub

    'Switches an individual LED OFF
    Sub LED_Off(x As Int, y As Int, z As Int)
        
    'Something like this:
        LED(x, y, z).State = False
    End Sub
    This project is really cool!! If you write such functions, I'll write a small game for it! :D
    On a bigger cube, we could even load 3D .obj files!!
     
    Peter Simpson and Cableguy like this.
  10. Erel

    Erel Administrator Staff Member Licensed User

    You can replace this code:
    Code:
    PinVcc(2).Initialize(0, PinVcc(2).MODE_OUTPUT)
        PinVcc(
    3).Initialize(1, PinVcc(3).MODE_OUTPUT)
        PinVcc(
    4).Initialize(2, PinVcc(4).MODE_OUTPUT)
        PinVcc(
    5).Initialize(3, PinVcc(5).MODE_OUTPUT)
        PinVcc(
    6).Initialize(4, PinVcc(6).MODE_OUTPUT)
        PinVcc(
    7).Initialize(5, PinVcc(7).MODE_OUTPUT)
        PinVcc(
    8).Initialize(6, PinVcc(8).MODE_OUTPUT)
        PinVcc(
    9).Initialize(7, PinVcc(9).MODE_OUTPUT)
        PinVcc(
    10).Initialize(8, PinVcc(10).MODE_OUTPUT)
        PinVcc(
    11).Initialize(9, PinVcc(11).MODE_OUTPUT)
        PinVcc(
    12).Initialize(10, PinVcc(12).MODE_OUTPUT)
        PinVcc(
    13).Initialize(11, PinVcc(13).MODE_OUTPUT)
        PinVcc(
    14).Initialize(12, PinVcc(14).MODE_OUTPUT)
        PinVcc(
    15).Initialize(13, PinVcc(15).MODE_OUTPUT)
    With:
    Code:
    For i = 2 To PinVCC.Length - 1
     PinVCC(i).Initialize(i - 
    2, PinVCC(i).MODE_OUTPUT)
    Next
     
    Peter Simpson, Beja and Cableguy like this.
  11. Cableguy

    Cableguy Expert Licensed User

    I have implemented a Led(x as int, ON as boolean) being x an int from 0 to 63...
    I will have a play with the x,y,Z suggestion
     
  12. Peter Simpson

    Peter Simpson Expert Licensed User

Loading...