Step 6The software
to insert the library inpout32.dll in c:\windows\system32 folder of your PC. You can this library typing the name on google or downloading the attached file PROGRAMMI.ZIP.
You can find some explanation (in English) about parallel port here: http://logix4u.net/Legacy_Ports/Parallel_Port.html
At every moment the status of the cube is stored in the StatoCubo matrix. Using a timer an event is generated every little ms and the state stored in the matrix is rappresented on the cube.
PS: the function of this module is to visualize on the cube the content of StatoCubo matrix. YOU MUST MANAGE BY YOURSELF THE CHANGES OF THE VALUES OF MATRIX!
If you want something already written, in attached file PROGRAMMI.ZIP you can found some programs that practically do everything:
Gestione led cube 0.5.3 --> manual management of the cube (including timeline)
level meter con monoton --> a free MP3 reader that controls led cube (equalization of output signal)
inpout32.dll --> library to manage parallel port (necessary for the execution of programs)
The StatoCubo matrix:
The StatoCubo matrix is composed by 8 vectors of 64 elements. Each vector represents the state of an entire layer, every element of the vector represents the state of 1 single one led: 1 = on, 0 = off
The ScriviCubo function:
This function is called by the timer event and his function is to transmit the content of the StatoCubo matrix to the real cube.
The ClokkaLed function:
This function is called by ScriviCubo function and it works by sending a clock signal to shift register of the columns ONLY modifying the bit of the clock. In this way the bit placed on input of the first shift register of the columns becames acquired.
The ClokkaLivello function:
This function is called by ScriviCubo function and it works by sending a clock signal to shift register of the layer ONLY modifying the bit of the clock. If the layer to activate is the first, an high signal (1) is placed on input of the shift register, for the next layer the bit on input is 0. In this way the bit for activation slides from one layer to the next one. The layer will be lighted in sequence, one at each time.
The ClearAll function:
This function enables the clear pin on both shift registers. All the bits in the shift register will be set to 0 and the cube will totally switch off.
The Aspetta function:
This function is used to delay the cycle of updating of each layer. Without this function, the leds of the each layer turns on and off too quickly for properly lighting.
Now we can pass to the real code, comments in bold:
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
'--------------------------COSTANT FOR LPT1 ADDRESS--------------------------------
Public Const IndirizzoData As String = "&H378" 'DATA REGISTER: 8 bit
'-------------------------------------------------------GLOBAL VARIABLES----------------------------------------------------
Public StatoCubo(1 To 8, 1 To 64) As Integer 'variable that contains the actual state of cube
'-------------------------------------------------------------FUNCTIONS--------------------------------------------------------
Public Function ScriviCubo(NumeroCicli As Integer) 'function for write into cube the state stored in StatoCubo matrix
Dim ByteLpt As Byte
Dim ContaLivelli As Integer
Dim ContaLed As Integer
Dim ContaCicli As Integer
For ContaCicli = 1 To NumeroCicli
For ContaLivelli = 1 To 8
'set all bit of shift reg. of columns without clocking on shift reg. of layers and disabling EVER all clear pins (xx 01x _1_)
For ContaLed = 64 To 1 Step -1 'For ContaLed = 1 To 64
'SHIFT REG. LAYERS:
'MSB (D5) = 0 --> clock disables
'CENTRAL (D4) = 1 (valore=16)--> clear disabled
'LSB (D3) = not important
'SHIFT REG. LED:
'MSB (D2) = 0 --> clock disabled
'CENTRAL (D1) = 1 (valore=2)--> clear disabled
'LSB (D0) = StatoCubo(ContaLivelli, ContaLed)
ByteLpt = (0 + 16 + 0) + (0 + 2 + StatoCubo(ContaLivelli, ContaLed))
Call ClokkaLed(ByteLpt) 'send the value at function that give 1 clock signal to the shift reg. of columns
Next ContaLed
'SHIFT REG. LAYERS:
'MSB (D5) = 0 --> clock disabled
'CENTRAL (D4) = 1 (valore=16)--> clear disabled
'LSB (D3) = (if layer = 1--> 1(value=8); if layer <> 1--> 0) --> set 1 only the fist time
'SHIFT REG. LED:
'MSB (D2) = 0 --> clock disabled
'CENTRAL (D1) = 1 (valore=2)--> clear disabled
'LSB (D0) = not important
If ContaLivelli = 1 Then 'if Im setting the first layer I send a 1 at the shift reg. of layers, after I will send only the clock signal
ByteLpt = (0 + 16 + 8) + (0 + 2 + 0)
Else
ByteLpt = (0 + 16 + 0) + (0 + 2 + 0)
End If
Call ClokkaLivello(ByteLpt) 'send value to the function that give a clock signal to the shift reg. of layers
Call Aspetta(60000) 'calling the function for generate a delay (the cube stops flashing from 60.000 to 70.000 cycles)
Next ContaLivelli 'restart the cycle for setting the next layer
Call ClearAll 'call the function for activate clear on all shift register (switch off all leds)
Next ContaCicli
End Function
Public Function ClokkaLed(Valore As Byte)
Out Val(IndirizzoData), Val(Valore) 'clock DISABLED
'add 4 because I want to set at 1 the clock bit of shift register of columns for giving clock signal
Out Val(IndirizzoData), Val(Valore + 4) 'clock ENABLED
End Function
Public Function ClokkaLivello(Valore As Byte)
Out Val(IndirizzoData), Val(Valore) 'clock DISABLED
'add 32 because I want to set at 1 the clock bit of shift reg. of layers for giving clock signal
Out Val(IndirizzoData), Val(Valore + 32) 'clock ENABLED
End Function
Public Function ClearAll() 'function for enable the clear pin on all shift register
Dim ByteLpt As Byte
'enabling clear on all shift register (value=0) (xx x0x x0x)
ByteLpt = 0 '00 000 000
Out Val(IndirizzoData), Val(ByteLpt)
End Function
Public Function Aspetta(Ncicli As Long) 'function used to delay the cycle of updating the each layers
Dim Contatore As Long
Dim Contato As Long
For Contatore = 0 To Ncicli
Contato = Contatore 'assignment operation (only for do a CPU operation)
Next Contatore
End Function
programmi.zip4 MB| « Previous Step | Download PDFView All Steps | Next Step » |























![Hard Wired LED Cube: [No Programming]](http://img.instructables.com/files/deriv/FTD/SF1T/GO8DC8KW/FTDSF1TGO8DC8KW.SQUARE.jpg)


















thanx
http://www.instructables.com/id/How-to-build-an-8x8x8-LED-cube-and-control-it-with/
Thanks in advance.