Thursday, December 23, 2010

 

The CUSB-36R Program For Flashing The Lights

The program that runs the christmas lights has several modes which you can switch between using the push button switch attached to P10.

The default is the music synchronising sequence.

This basically works using 3 equally sized arrays of integers.

Data1 - each bit controls one chanel P40-P47. When a bit is on the light will be on. 0 - all off, 255 - all on.
Data2 - each bit controls one chanel P4-P7, P16, P17, P22, P23
Data3 - specifies the number of miliseconds before the next item is processed.
DataLen - specified the number of items in the 3 arrays.

Once done it automatically starts again.

The program also has the logic which allows a switch attached to P11 and P12 to stop and restart the sequence. This is done by closing the P11 wires which puts the program in a suspended state until P12 is closed at which time it goes back to the start and plays again. As we will see later I have attached P11 and P12 to relays controlled by the Velleman K8055 to allow the light sequence to be synched with music. Whenever the music restarts the box is reset by these two relays.

The second mode loops through displaying each chanel in turn.

The remaining modes switch on an hold one chanel at a time.

The circuit is synchronous so you have to hold in the P10 button until the current sleep is completed before the program will sense it and change to the next mode.

Realistically I leave it in default mode unless I am troubleshooting something.

So here is the code. It is reasonably well commented.






' The device specified
Const Device = CB280

' milliseconds to sleep for
Dim sleep As Integer
sleep = 500

Dim mode As Integer
mode = 1
' 0 - Default cycle all lights 2 at a time
Dim count1 As Byte
count1 = 0
' 1 - Play the xmas tunes
Dim mode1current As Integer
mode1current = 0
' 2-17 - test 1 channel at a time

'
' Insert your light data here
'

Const Byte DATA1 = ( 0, 0, 36, 0, 36, 0, 36, 0, 36, 0, 36, 0, 36, 109, 0, 146, 36, 73, 146, 36, 73, 128, 64, 32, 64, 128, 0, 16, 8,
4, 8, 16, 2, 1, 0, 1, 2, 16, 8, 4, 8, 219, 146, 36, 73, 146, 36, 73, 192, 24, 3, 0, 73, 96, 12, 1, 160, 20, 2, 192, 20, 1, 160, 12,
3, 96, 24, 0, 128, 64, 32, 16, 8, 4, 2, 1, 0, 16, 8, 4, 0, 128, 64, 32, 16, 8, 4, 2, 1, 0, 16, 8, 146, 73, 36, 128, 144, 18, 2, 146,
0, 64, 72, 9, 1, 73, 0, 146, 73, 36, 146, 73, 36, 146, 73, 36, 146, 73, 36, 146, 206, 0, 146, 36, 73, 146, 36, 73, 128, 64, 32, 64,
128, 0, 16, 8, 4, 8, 16, 2, 1, 0, 1, 2, 16, 8, 4, 8, 213, 146, 36, 73, 146, 36, 73, 128, 64, 32, 64, 128, 0, 16, 8, 4, 8, 16, 2,
1, 0, 1, 2, 16, 8, 4, 8, 0, 128, 64, 32, 16, 8, 4, 2, 1, 0, 16, 8, 4, 0, 128, 64, 32, 16, 8, 4, 2, 1, 0, 16, 8, 146, 73, 36, 128,
144, 18, 2, 146, 0, 64, 72, 9, 1, 73, 0, 146, 73, 36, 146, 73, 36, 146, 73, 36, 146, 73, 36, 146, 206, 36, 146, 36, 73, 146, 36,
73, 128, 64, 32, 64, 128, 0, 16, 8, 4, 8, 16, 2, 1, 0, 1, 2, 16, 8, 4, 8, 73, 146, 36, 73, 146, 36, 73, 128, 64, 32, 64, 128, 0,
16, 8, 4, 8, 16, 2, 1, 0, 182, 219, 109, 182, 219, 109, 0, 109, 0, 0, 128, 144, 146, 147, 152, 219, 36, 0, 8, 65, 8, 65, 65, 32,
4, 0, 146, 109, 0, 36, 146, 73, 0, 73, 219, 16, 130, 16, 130, 130, 64, 8, 1, 36, 0, 64, 8, 12, 2, 18, 146, 73, 4, 32, 4, 32, 32,
128, 16, 2, 73, 109, 0, 36, 146, 109, 219, 216, 192, 2, 1, 2, 8, 4, 8, 128, 64, 32, 0, 64, 8, 12, 2, 18, 146, 73, 4, 32, 4, 32, 32,
128, 16, 2, 73, 128, 32, 16, 4, 2, 0, 1, 65, 109, 0, 36, 146, 73, 0, 73, 219, 16, 130, 16, 130, 130, 64, 8, 1, 36, 0, 64, 8, 12,
2, 18, 146, 73, 4, 32, 4, 32, 32, 128, 16, 2, 73, 109, 0, 36, 146, 109, 219, 216, 192, 2, 1, 2, 8, 4, 8, 128, 64, 32, 0, 64, 8, 12,
2, 18, 146, 73, 4, 32, 4, 32, 32, 128, 16, 2, 73, 255, 219, 109, 219, 109, 0, 128, 16, 2, 0, 128, 0, 16, 0, 2, 0, 64, 0, 8, 0, 1,
0, 32, 0, 4, 0, 0, 0, 0, 128, 16, 2, 64, 8, 1, 32, 4, 0, 128, 16, 2, 64, 8, 1, 32, 4, 0, 128, 16, 2, 64, 8, 1, 0, 128, 136, 136,
64, 68, 70, 32, 48, 49, 136, 0, 70, 0, 49, 0, 136, 0, 70, 0, 49, 146, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32,
0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 146, 0, 146, 0, 146, 0, 146, 0, 0, 146, 0, 146, 0, 146, 73, 0, 146,
0, 146, 0, 146, 0, 146, 0, 146, 128, 136, 136, 64, 68, 70, 32, 48, 49, 146, 73, 36, 146, 73, 36, 146, 73, 36, 73, 128, 136, 136,
64, 68, 70, 32, 48, 0, 146, 0, 73, 0, 36, 0, 219, 136, 0, 70, 0, 49, 0, 136, 0, 70, 0, 49, 146, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65,
0, 4, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 146, 0, 128, 136, 136, 64, 68, 70, 32, 48,
49, 146, 73, 36, 146, 73, 36, 146, 73, 36, 73, 128, 136, 136, 64, 68, 70, 32, 48, 0, 146, 0, 73, 0, 36, 0, 219, 136, 0, 70, 0, 49,
0, 136, 0, 70, 0, 49, 146, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32,
0, 16, 0, 65, 0, 4, 146, 0, 128, 136, 136, 64, 68, 70, 32, 48, 49, 146, 73, 36, 146, 73, 36, 146, 73, 36, 73, 128, 136, 136, 64,
68, 70, 32, 48, 0, 146, 0, 73, 0, 36, 0, 219, 136, 0, 70, 0, 49, 0, 136, 0, 70, 0, 49, 146, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0,
4, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 146, 0, 128, 136, 136, 64, 68, 70, 32, 48, 49,
146, 73, 36, 146, 73, 36, 146, 73, 36, 73, 128, 136, 136, 64, 68, 70, 32, 48, 0, 146, 0, 73, 0, 36, 0, 219, 136, 0, 70, 0, 49, 0,
136, 0, 70, 0, 49, 146, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32, 0, 16, 0, 65, 0, 4, 0, 130, 0, 8, 0, 32, 0,
16, 0, 65, 0, 4, 146, 0, 128, 136, 136, 64, 68, 70, 32, 48, 49, 146, 73, 36, 146, 73, 36, 146, 73, 36, 73, 128, 136, 136, 64, 68,
70, 32, 48, 0, 146, 0, 73, 0, 36, 0, 219, 0, 219, 0, 219, 0, 219, 0, 0)
Const Byte DATA2 = ( 0, 0, 200, 0, 200, 0, 200, 0, 200, 0, 200, 0, 200, 164, 18, 72, 200, 72, 20, 148, 20, 40, 40, 40, 40, 40, 0,
18, 18, 18, 18, 18, 18, 18, 146, 18, 18, 18, 18, 18, 18, 40, 68, 196, 68, 40, 168, 40, 18, 18, 18, 18, 18, 72, 72, 200, 72, 72, 200,
72, 72, 200, 72, 72, 72, 72, 72, 0, 72, 34, 20, 72, 34, 20, 72, 34, 148, 72, 34, 20, 0, 72, 34, 20, 72, 34, 0, 72, 34, 148, 72, 34,
64, 8, 192, 40, 40, 40, 40, 40, 0, 68, 68, 68, 68, 68, 0, 40, 40, 168, 40, 40, 168, 40, 40, 168, 40, 40, 168, 40, 168, 66, 66, 194,
66, 40, 168, 40, 20, 20, 20, 20, 20, 0, 72, 36, 18, 72, 36, 18, 72, 164, 18, 72, 36, 18, 72, 36, 168, 72, 200, 72, 34, 162, 34, 20,
20, 20, 20, 20, 0, 72, 72, 72, 72, 72, 72, 72, 200, 72, 72, 72, 72, 72, 72, 0, 40, 40, 40, 40, 40, 24, 24, 24, 152, 24, 24, 24, 0,
72, 72, 72, 72, 72, 0, 40, 40, 168, 40, 40, 16, 72, 160, 24, 24, 24, 24, 24, 0, 72, 72, 72, 72, 72, 0, 40, 40, 168, 40, 40, 168,
40, 40, 168, 40, 40, 168, 40, 168, 152, 24, 152, 24, 24, 152, 24, 24, 24, 24, 24, 24, 0, 72, 72, 72, 72, 72, 72, 72, 200, 72, 72,
72, 72, 72, 72, 40, 24, 152, 24, 24, 152, 24, 24, 24, 24, 24, 24, 0, 68, 36, 20, 68, 36, 20, 68, 164, 148, 68, 164, 148, 68, 164,
18, 200, 0, 0, 72, 72, 72, 72, 72, 72, 200, 72, 72, 72, 72, 72, 72, 72, 72, 200, 72, 162, 34, 162, 34, 34, 34, 34, 34, 72, 34, 20,
72, 34, 20, 72, 34, 148, 72, 72, 72, 72, 72, 72, 72, 72, 72, 162, 20, 200, 162, 20, 72, 34, 20, 162, 34, 162, 34, 162, 34, 34, 34,
72, 34, 20, 72, 34, 20, 72, 34, 20, 20, 20, 20, 20, 20, 20, 20, 20, 72, 162, 20, 200, 162, 20, 72, 34, 20, 72, 72, 72, 72, 72, 200,
72, 72, 162, 34, 162, 34, 34, 34, 34, 34, 72, 34, 20, 72, 34, 20, 72, 34, 148, 20, 20, 20, 20, 20, 20, 20, 20, 72, 162, 20, 200,
162, 20, 72, 34, 20, 200, 72, 200, 72, 200, 72, 72, 72, 72, 34, 20, 72, 34, 20, 72, 34, 20, 36, 36, 36, 36, 36, 36, 36, 36, 72, 162,
20, 200, 162, 20, 72, 34, 20, 200, 34, 148, 72, 162, 20, 72, 34, 20, 0, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
72, 200, 72, 72, 34, 34, 34, 34, 34, 34, 34, 34, 162, 34, 34, 34, 34, 34, 34, 34, 34, 162, 34, 34, 34, 34, 34, 34, 34, 20, 20, 148,
20, 20, 20, 20, 20, 20, 200, 72, 72, 72, 72, 72, 200, 72, 72, 72, 72, 72, 72, 34, 34, 34, 34, 162, 34, 34, 34, 34, 34, 34, 20, 20,
20, 20, 20, 148, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 148, 20, 20, 20, 20, 20, 20, 20, 0, 72, 0, 72, 0, 72, 0, 0, 72, 0, 72,
0, 72, 0, 0, 72, 0, 72, 0, 72, 0, 72, 0, 72, 34, 34, 162, 34, 20, 20, 20, 20, 20, 72, 72, 200, 72, 72, 200, 72, 72, 200, 72, 34,
34, 162, 34, 20, 20, 20, 20, 20, 0, 72, 72, 72, 200, 72, 72, 162, 34, 34, 34, 34, 34, 162, 34, 34, 34, 34, 34, 34, 20, 20, 20, 20,
148, 20, 20, 20, 20, 20, 20, 72, 72, 72, 72, 72, 200, 72, 72, 72, 72, 72, 72, 72, 34, 34, 34, 34, 162, 34, 34, 34, 34, 34, 34, 34,
0, 20, 20, 148, 20, 72, 72, 72, 72, 72, 34, 34, 162, 34, 34, 162, 34, 34, 162, 34, 20, 20, 148, 20, 72, 72, 72, 72, 72, 72, 34, 34,
34, 162, 34, 34, 148, 20, 20, 20, 20, 20, 200, 72, 72, 72, 72, 72, 0, 34, 34, 34, 34, 162, 34, 34, 34, 34, 34, 0, 20, 20, 20, 20,
20, 148, 20, 0, 72, 72, 72, 72, 72, 72, 72, 72, 72, 200, 72, 72, 72, 72, 72, 72, 0, 0, 34, 34, 162, 34, 20, 20, 20, 20, 20, 72, 72,
200, 72, 72, 200, 72, 72, 200, 72, 34, 34, 162, 34, 20, 20, 20, 20, 20, 0, 72, 72, 72, 200, 72, 72, 162, 34, 34, 34, 34, 34, 162,
34, 34, 34, 34, 34, 34, 20, 20, 20, 20, 148, 20, 20, 20, 20, 20, 0, 72, 72, 72, 72, 72, 200, 72, 72, 72, 72, 72, 72, 72, 34, 34,
34, 34, 162, 34, 34, 34, 34, 34, 34, 34, 0, 20, 20, 148, 20, 72, 72, 72, 72, 72, 34, 34, 162, 34, 34, 162, 34, 34, 162, 34, 20, 20,
148, 20, 72, 72, 72, 72, 72, 0, 34, 34, 34, 162, 34, 34, 148, 20, 20, 20, 20, 20, 148, 20, 20, 20, 20, 20, 20, 72, 72, 72, 72, 200,
72, 72, 72, 72, 72, 72, 34, 34, 34, 34, 34, 162, 34, 34, 34, 34, 34, 34, 34, 34, 20, 20, 20, 148, 20, 20, 20, 20, 20, 20, 20, 0,
72, 72, 200, 72, 34, 34, 34, 34, 34, 20, 20, 148, 20, 20, 148, 20, 20, 148, 20, 72, 72, 200, 72, 34, 34, 34, 34, 34, 0, 20, 20, 20,
200, 34, 20, 72, 72, 72, 72, 72, 72, 72, 72)
Const Integer DATA3 = ( 250, 370, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 155, 155, 310, 310, 620, 310, 310, 620, 310,
310, 465, 155, 930, 310, 310, 310, 465, 155, 310, 310, 310, 155, 155, 310, 310, 310, 310, 620, 310, 310, 310, 620, 310, 310, 620,
310, 310, 465, 155, 930, 310, 310, 310, 465, 155, 310, 310, 310, 310, 310, 310, 310, 310, 310, 620, 310, 310, 310, 310, 930, 155,
155, 310, 310, 310, 310, 930, 310, 310, 310, 310, 310, 930, 310, 310, 310, 310, 310, 465, 155, 155, 155, 310, 310, 310, 310, 930,
310, 310, 310, 310, 310, 930, 155, 155, 310, 310, 310, 310, 310, 310, 465, 155, 310, 310, 310, 310, 620, 310, 310, 310, 620, 310,
310, 620, 310, 310, 465, 155, 930, 310, 310, 310, 310, 465, 155, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 310, 620,
310, 310, 620, 310, 310, 465, 155, 930, 310, 310, 310, 465, 155, 310, 310, 310, 155, 155, 310, 310, 310, 310, 620, 310, 310, 310,
310, 310, 930, 155, 155, 310, 310, 310, 310, 930, 310, 310, 310, 310, 310, 930, 310, 310, 310, 310, 310, 620, 155, 155, 155, 310,
310, 310, 310, 930, 310, 310, 310, 310, 310, 930, 155, 155, 310, 310, 310, 310, 310, 310, 465, 155, 310, 310, 310, 310, 620, 310,
310, 310, 620, 310, 310, 620, 310, 310, 465, 155, 930, 310, 310, 310, 310, 465, 155, 310, 310, 310, 310, 310, 310, 310, 310, 310,
310, 310, 310, 620, 310, 310, 620, 310, 310, 465, 155, 930, 310, 310, 310, 310, 465, 310, 620, 620, 620, 620, 620, 620, 620, 620,
2480, 155, 155, 8510, 457, 442, 147, 295, 295, 295, 295, 295, 295, 147, 147, 147, 147, 442, 147, 295, 295, 590, 442, 147, 295, 295,
295, 295, 295, 295, 147, 147, 147, 147, 442, 147, 295, 295, 590, 442, 147, 295, 295, 295, 295, 295, 295, 147, 147, 147, 147, 442,
147, 295, 295, 590, 442, 147, 295, 295, 442, 147, 295, 295, 147, 147, 295, 147, 147, 295, 295, 295, 590, 442, 147, 295, 295, 295,
295, 295, 295, 147, 147, 147, 147, 442, 147, 295, 295, 590, 147, 295, 147, 147, 295, 295, 295, 590, 442, 147, 295, 295, 295, 295,
295, 295, 147, 147, 147, 147, 442, 147, 295, 295, 590, 442, 147, 295, 295, 295, 295, 295, 295, 147, 147, 147, 147, 442, 147, 295,
295, 590, 442, 147, 295, 295, 442, 147, 295, 295, 147, 147, 295, 147, 147, 295, 295, 295, 590, 442, 147, 295, 295, 295, 295, 295,
295, 147, 147, 147, 147, 442, 147, 295, 295, 590, 295, 295, 295, 295, 885, 295, 590, 590, 1180, 4500, 1027, 1027, 1027, 1027, 1027,
1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018,
1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 1018, 461, 461, 231, 692, 461, 231,
231, 231, 692, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 115, 346, 922, 231, 231, 346, 115, 461, 231, 231, 461, 231, 231,
692, 231, 231, 231, 231, 231, 231, 231, 461, 231, 231, 231, 231, 922, 231, 231, 231, 231, 461, 115, 346, 231, 231, 231, 231, 692,
231, 231, 231, 231, 231, 231, 461, 231, 231, 231, 231, 231, 922, 231, 231, 231, 231, 461, 461, 231, 231, 231, 231, 922, 461, 461,
231, 692, 461, 231, 231, 231, 692, 231, 231, 231, 231, 461, 231, 231, 461, 461, 922, 461, 461, 231, 692, 461, 231, 231, 231, 692,
231, 231, 231, 231, 461, 461, 1845, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 115, 346, 922, 231, 231, 346, 115, 461, 231,
231, 461, 231, 231, 692, 231, 231, 231, 231, 231, 231, 231, 461, 231, 231, 231, 231, 922, 231, 231, 231, 231, 461, 115, 346, 231,
231, 231, 231, 692, 231, 461, 461, 231, 692, 461, 231, 231, 231, 692, 231, 231, 231, 231, 461, 231, 231, 461, 461, 922, 461, 461,
231, 692, 461, 231, 231, 231, 692, 231, 231, 231, 231, 461, 461, 1845, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 115, 346,
922, 231, 231, 346, 115, 461, 231, 231, 461, 231, 231, 692, 231, 231, 231, 231, 231, 231, 231, 461, 231, 231, 231, 231, 922, 231,
231, 231, 231, 461, 115, 346, 231, 231, 231, 231, 692, 231, 461, 461, 231, 692, 461, 231, 231, 231, 692, 231, 231, 231, 231, 461,
231, 231, 461, 461, 922, 461, 461, 231, 692, 461, 231, 231, 231, 692, 231, 231, 231, 231, 461, 461, 1845, 231, 231, 231, 231, 231,
231, 231, 231, 231, 231, 115, 346, 922, 231, 231, 346, 115, 461, 231, 231, 461, 231, 231, 692, 231, 231, 231, 231, 231, 231, 231,
461, 231, 231, 231, 231, 922, 231, 231, 231, 231, 461, 115, 346, 231, 231, 231, 231, 692, 231, 461, 461, 231, 692, 461, 231, 231,
231, 692, 231, 231, 231, 231, 461, 231, 231, 461, 461, 922, 461, 461, 231, 692, 461, 231, 231, 231, 692, 231, 231, 231, 231, 461,
461, 1845, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 115, 346, 922, 231, 231, 346, 115, 461, 231, 231, 461, 231, 231, 692,
231, 231, 231, 231, 231, 231, 231, 461, 231, 231, 231, 231, 922, 231, 231, 231, 231, 461, 115, 346, 231, 231, 231, 231, 692, 231,
461, 461, 231, 692, 461, 231, 231, 231, 692, 231, 231, 231, 231, 461, 231, 231, 461, 461, 922, 461, 461, 231, 692, 461, 231, 231,
231, 692, 231, 231, 231, 231, 461, 461, 1845, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 2963)
Const DATALEN = 967

'
' End inserted light data
'

' loop forever
Do
' If P10 is pressed then we need to change modes

If In(10) = 1 Then

' increment mode
mode = mode + 1

' If we are greater than mode 17 then loop back to zero
If mode > 17 Then
mode = 0
End If

' reset mode variables to their default
mode1current = 0
count1 = 1

' turn off all the lights
Clear

' reset the sleep timer
sleep = 500

' for modes 2-17 just set the right channel on
If mode = 2 Then
Clear
Out 7, 1
Elseif mode = 3 Then
Clear
Out 6, 1
Elseif mode = 4 Then
Clear
Out 5, 1
Elseif mode = 5 Then
Clear
Out 4, 1
Elseif mode = 6 Then
Clear
Out 23, 1
Elseif mode = 7 Then
Clear
Out 22, 1
Elseif mode = 8 Then
Clear
Out 17, 1
Elseif mode = 9 Then
Clear
Out 16, 1
Elseif mode = 10 Then
Clear
Out 40, 1
Elseif mode = 11 Then
Clear
Out 41, 1
Elseif mode = 12 Then
Clear
Out 42, 1
Elseif mode = 13 Then
Clear
Out 43, 1
Elseif mode = 14 Then
Clear
Out 44, 1
Elseif mode = 15 Then
Clear
Out 45, 1
Elseif mode = 16 Then
Clear
Out 46, 1
Elseif mode = 17 Then
Clear
Out 47, 1
End If

' wait for the user to release P10 otherwise we might jump a mode
Do While In(10) = 1
Wait 10
Loop

End If

' if we are in mode 0 - turn on 1 outlet from each group of 8
If mode = 0 Then

' set the lights
PopulateOutbytes count1, count1

' prepare our next lights by shifting our set bit one to the right
count1 = count1 * 2

' if all would be off or we have gone beyond 8 bits reset to 1
If count1 = 0 Or count1 > 128 Then
count1 = 1
End If

' if we are in mode 1 - our main christmas light routine
Elseif mode = 1 Then

' if P11 circuit is closed then we need to stop and get ready to restart. We stay in this state until P12 is closed.
If In(11) = 1 Then
' Turn off all the lights
Clear

' go back to the beginning of the array
mode1current = 0

' we expect P12 should be open right now so wait until it is
Do While In(12) = 0
Wait 10
Loop

' now wait until it is closed
Do While In(12) = 1
Wait 10
Loop

' now we can continue
End If

' as long as we have not finished our arrays
If mode1current <>
' turn on the appropriate lights
PopulateOutbytes DATA1(mode1current), DATA2(mode1current)

' get the sleep time ... ie how long to leave the lights on for
sleep = DATA3(mode1current)

' move to the next array entry
mode1current = mode1current + 1

' a zero sleep is invalid ... default to 1/2 a second
If sleep = 0 Then
sleep = 500
End If

Else

' we have reched the end of the array ... loop back to the beginning after 1/2 a second

' turn the lights off
Clear

' move to the start
mode1current = 0

' sleep for 1/2 a second
sleep = 500

End If

End If

' if for some reason P11 is closed then jump to mode 1 and handle the reset event as normal.
If In(11) = 1 Then
mode = 1
' if P10 is closed then skip the sleep so we go straight to mode switch processing
Elseif In(10) = 1 Then
Else
' sleep the right amount of time
Wait sleep
End If

Loop

' This function takes the two bytes and turns the appropriate circuits on and off
Sub PopulateOutbytes(b1 As Byte, b2 As Byte)

' These are the ports mapped to ByteOuts on the CUSB. The doco here is awful but this works
'0 - 0-7
'1 - 8-15 (input only)
'2 - 16-23
'3 - 24-31
'4 - 32-39
'5 - 40-47

' this is how the bytes are mapped to the Ports
' port 5 - b1
' BIT 128 64 32 16 8 4 2 1
' PORT 47 46 45 44 43 42 41 40

' port 0 - b2
' BIT 128 64 32 16 8 4 2 1
' PORT 7 6 5 4 xx xx xx xx

' port 2 - b2
' BIT 128 64 32 16 8 4 2 1
' PORT 23 22 xx xx xx xx 17 16

' these are the bytes that will be sent to the three ports
Dim outbyte0 As Byte
Dim outbyte2 As Byte
Dim outbyte5 As Byte

' byte 5 is easy it is a direct copy of B1
outbyte5 = b1

' B2 is hard as some bits in byte 2 and byte 0 need to be set. This code does that
outbyte2 = 0
If b2 And 16 Then
outbyte2 = outbyte2 + 128
End If
If b2 And 32 Then
outbyte2 = outbyte2 + 64
End If
If b2 And 64 Then
outbyte2 = outbyte2 + 2
End If
If b2 And 128 Then
outbyte2 = outbyte2 + 1
End If

outbyte0 = 0
If b2 And 1 Then
outbyte0 = outbyte0 + 128
End If
If b2 And 2 Then
outbyte0 = outbyte0 + 64
End If
If b2 And 4 Then
outbyte0 = outbyte0 + 32
End If
If b2 And 8 Then
outbyte0 = outbyte0 + 16
End If

' Now we can set the light circuits
Byteout 5,outbyte5
Byteout 0,outbyte0
Byteout 2,outbyte2

End Sub

' Debugging routine used to flash a port for 1/5th second
Sub Ping(d As Integer)
Out d,1
Wait 200
Out d,0
End Sub

' Turn all the lights off
Sub Clear()
Byteout 5,0
Byteout 0,0
Byteout 2,0
End Sub





In my next post we will look at how I generated 967 items in the arrays without going totally insane.

 

The CUSB-36R Christmas Light Circuit

This is the circuit diagram for the Comfile CUSB-36R Programmed Christmas Lights. If it is a little hard to read drop me an email at keithsw1@yahoo.com and I will return a more detailed schematic.



Basically the Comfile CUSB-36R can either directly drive mains powered devices or it can drive relays to switch mains powered devices. There are two groups of 8 in this circuit diagram.

I have chosen to switch ports P40-P47 directly. This limits their total current draw to 5Amps which is protected in this diagram by the 5A fuse. Make sure you wire this in correctly and test that when the fuse is removed the circuit stops working. I accidentally miswired my fuse and burnt out one half of my circuit due to too much current draw.

The other 8 circuits are switched using high current 24V relays. This alows me to switch much greater currents without damaging the CUSB-36R.

The switch attached to P10 is used as an input to control the playback mode the device is in. To change modes you press and hold until it is sensed.

The other inputs P11, P12 and P13 are attached to a Cat-5 lan cable which connects to the Velleman K8055 and are used to synch the computer to the lights that are flashed by the CUSB-36R. There is also a 24V line which is used to power the relays the K8055 will close to trigger the P11, P12 and P13 inputs.

To do the power sockets on the cheap I bought 16 2m Arlec extension cords and cut the plug end off it. This works really well as the leads hang out of the box which means the box does not need a large surface area to hold all the sockets.

In my next post we will look at the program that runs the light show.

Labels:


Sunday, December 05, 2010

 

Christmas Lights

It is that time of year and as usual we have our lights up on the house.

This year after being inspired by some YouTube videos of lights set to music I decided to investigate what it would take to get my lights set to music.

It turns out to not be a cheap thing to do but with a bit of know how and some perseverance I got it all working. By building it myself I managed to also get a huge amount of flexibility out of it as well.

I had a few mis-steps along the way ... in part due to the vagueness of documentation and a lack of good examples on the web.

I thought it was time to rectify that so I thought I would put up some posts on how I got it all working.

There are really only a couple of major components which are wired together along with some software I wrote on the PC and the PLC controller board that actually drives the lights.



The core components are the Comfile CUSB-36R and the Velleman K8055.

The CUSB-36R is the core of the unit. It runs a program that through relays turns power circuits on an off. In fact if you just want to control your lights using a custom flashing sequence this is pretty much the component that does it all.

The K8055 is a PC USB interface card. I use it to allow a laptop to tell the CUSB-36R when it should start its program. In that way I am able to synchronise the music the computer plays with the lights the CUSB-36R flashes.

In my next post we will look at how I set up the CUSB-36R.

Friday, December 02, 2005

 

Building new machines

In the past 6 months I have built 2 new machines and rebuilt my old machine and along the way run more setup programs than I care to remember. In preparing for this process I have dug through my archives of downloaded and purchased software in an attempt to identify only those programs I absolutely need and those which are useful.

As I am sure many people go through this process I thought I might dedicate a couple of posts to listing out some of those core software products and why I install them.

Let me start out a bit radical with Virus software ... How many times have I read that this is an essential piece of software that you must install yadda yadda yadda. Bullshit. Virus scanners are a scam. They slow down your PC and unless you are stupid absolutely useless.

I have run machines for almost 20 years and the last virus I saw detected by a scanner was back in 1990 when it was a boot sector virus on a floppy disk. While it is true that trojans etc can attack you if the following statements are true then I suggest you delete your antivirus, save yourself the annual fee and speed up your machine:

- Is you machine behind a NAT.
- Do you run a quality firewall (not the windows one).
- Are you smart enough not to download unknown email attachments
- Do you run spyware detectors.
- Do you use windows update to automatically apply windows patches

If this is all true then you dont need a virus scanner. If anything is not true either change yourself or stick with a virus scanner. AVG have a free one available.

Now that that is out of the way lets talk about firewalls. The windows XP one does not cut it. It prevents those outside your machine accessing you but once your machine is compromised it wont prevent adware etc from calling home. I use ZoneAlarm from ZoneLabs. I only use the free version but it offers sufficient protection to be worth the additional install.

Adware is a major problem these days and rumour is you should run multiple detectors to be sure. I run Adaware once every couple of weeks and SpyBot once in a blue moon. I cant remember the last time it found anything more serious than a cookie file but having seen what adware can do to a mates pc (I swear he had over 20 types installed) I think it is worth the hassle. What I also like about this stuff is it does not run all the time soaking up precious cpu cycles. Both of these products can be downloaded for free for personal use.

The final software product I want to talk about is autoruns from http://www.sysinternals.com . These guys produce a bunch of free utilities for the more technically minded user and autoruns is one of the more useful. These days every program you install seems to have some program that runs in the background with an icon in the system tray. These things slow down your machine and add little in the way of benefits in most situations. Autoruns can help you to stop these from running each time you log in helping your machine to run just a bit faster. Mind you autoruns is not for the fainthearted. These guys know their technology but dont write tools for novice users.

More next time.

Friday, November 25, 2005

 

T'is the season to hunt for broken lightbulbs

Twelve years ago the wife brought home her 1st box of christmas lights and asked me if I would hang them off the gutters on the roof. It seemed like a simple request which I complied with.

The next year there were 2 boxes and a santa and a reindeer pattern that needed to be cut our of plywood and painted.

This year there are over 40 boxes of lights, moving reindeer, blow up santas and the original plywood painted santa and reindeer. They take 2 days to put up and several nights to get right including hours spent trying to find the one blown light bulb that is stopping 20 other lights from working.

We are not the only ones of course. Several of my neighbours are into it as well. Despite the relative inascessibility of our street (well away from the main road) we get a steady stream of cars and visitors on foot. I can't imagine this happening in the colder climates but in Sydney its summer and a night wandering the suburbs looking at christmas lights can be a great way to keep the pounds off.

When you end up with this many christmas lights you need to be organised. Last year I threw out my original box of lights as the wiring finally gave out. Careful care for lights can mean they will last for years as long as you treat them right. I thought I would list out some hints on how to do the christmas light thing without going insane.

1. Have a high paying job. Doing the christmas light thing is not cheap. Lights cost between $10 and over $100 each. Typically you get way you pay for. Cheap ones typically do very little and dont last. More expensive lights are typically more interesting and if handled right last longer.

2. LED lights are low maintenance but once they fail you have to throw them out. It says on the box that you cant fix them and generally you can't. There is one exception. If you know exactly which LED has failed you can work around it by shorting it out.

3. If you have bulbs buy a bulb tester. While you can find a broken bulb without one ... they cost less than $2 and they save a heap of time.

4. If you are going to buy more than 2 of a single type of light then you are better off buying a 3rd for spare bulbs than buying spare bulbs in packets. Spare bulb packets give you 5-10 bulbs usually 1-2 of each colour. The price for these few spares is exhorbitant compared to the original cost of the sets so buying an extra set for spares almost always pays off.

5. When your lights finally die throw them out but remove the bulbs first. In lieu of 4 above scavenging the lights from sets you are throwing out can provide you with planty of spares. Of course not every set takes the same sort of bulbs so this is not perfect but these days I find I rarely need to buy a spare bulb.

6. Label everything. Once you start to accumulate sets of lights it is important you label the adaptors and the lights themselves otherwise you will start to mix them up. Mixing up adaptors with the wrong lights is a great way to ruin them. I label mine with masking tape and a marker.

7. Keep a spreadsheet of your lights including details such as:
- The label on each set
- The manufacturer - useful if you have to buy bulbs
- The Voltage and wattage of the replacement bulbs - also useful if you have to buy bulbs. Remember Wattage = Volts x Amps.
- Where you hung the lights
- Where you plugged them in
- Any extras you needed such as extension cords

8. Buy a fishing tackle box (or 4) to keep all those spare bulbs in. Remember to label the compartments with the Watts and Volts of the globes you put in them.

9. If you tend to put the lights up in the same palce each year then spending a little bit more time preparing mounts to hang the lights on can save a huge amount of time when you come to hang them next year. Most mounts are small enough that they dont look bad even if left in place for the whole year. My favourite mounts are cable clamps with the nail through them. I remove the nail and replace it with a screw which I then either screw into wood or into a plug I insert in the brick work. It then only takes seconds to hang the lights the following year on these existing mounts.

10. My final suggestion is to go out and buy a pack of 500 nylon wire ties. These little pieces of plastic are useful for tying up lights and keeping your cables tidy. I use several hundred each year. They are a lot easier than alternatives like string and looping lights around things

Now I have a month of testing for broken bulbs before I get to spend another whole day pulling them all down and packing them up in boxes for another year. It is a lot of work but my wife, kids and the steady stream of visitors really get a kick out of it and I guess I get a kick out of that.

Wednesday, November 16, 2005

 

ASUS A8V-E Deluxe Chipset Fan

While I have been away from this Blog posting thingy I have purchased and installed 2 new PCs. In fact it was this that forced me to resolve my wireless aerial issue.

The first of these machines I use to drive a LCD television. It is an AMD 3200+ machine with the above mentioned ASUS A8V-E Deluxe motherboard. While I have been reasonably happy with its performance I have found it very noisy. I have it in a cupboard with an open back to expel hot air and holes in the bottom to let in new cold air.

A few weeks ago it started to periodically make horrible grinding noises. This is never a good thing. A quick inspection showed it to be the chipset fan. This is a small 4cm fan that spins at over 9000rpm to keep the northbridge/southbridge chip cool.

A quick scan on the internet led me to a number of discussions where people had similar problems on this and a couple of other ASUS boards. A call to ASUS confirmed they were happy to replace the fan (not the board) under warranty as long as I could provide the serial number of the board. I had some trouble locating it due to the inaccessibility of the machine and the fact I did not want to unplug everything. In the end I did not find it (apparently it is near the main power plug). However it is also on the box which I do have so I grabbed it from there.

I then dropped by their support site in Sydney in Silverwater. Walked in stated my problem and the guy returned in 2 mins flat with a new fan. On my way out of the building I had the uncomfortable feeling the fan was not right. While I did not have my old fan there I was sure the mountings were in the wrong place.

So I went back in and another 5 minutes later he came out with a heatsink. Apparently they dont use fans anymore but instead use a 3 cm high heatsink. This is great news on the noise front but as I walked out of the store I became concerned again that there was no head transfer goo on the heatsink and I didnt have any at home.

15 mins later I had another heatsink with the goo attached and on my way home.

The next challenge was to get the old fan off. The right way to do this is to remove the motherboard and squeeze the back side of the plastic pins than hold the fan down. I just pulled them out with a pair of pliers. This means I wont be able to remount the fan but hey I cant imagine why I would want to at any rate and it did not dame the board.

Of course getting the pins off is only part of the problem. It was still stuck to the chip. So I unplugged the fan power lead and turned on the machine. 3 mins later the fan easily twisted off the motherboard.

Attaching the heatsink was a breeze and now I have an incredibly quiet machine.

 

Aerial problem resolved

It took until July but I finally got motivated to sort out my aerial problem. It turned out it had nothing to do with my aerial per se but was a problem with my DWL-2100AP which was using its internal rather than external aerial. Not surprisingly this meant attaching the aerial made no difference.

Of course this fact was not easy to find out and changing the setting is not possible through the friendly browser interface ... noooo .... instead you have to telnet to the box and type in a set command. Not the most accessible way to change the aerial it uses.

So all fixed now. I have 802.11g access from as much as 200 metres away with good connectivity even at the back of the house across the street.

This page is powered by Blogger. Isn't yours?