An LED circus

bove a

The LED-circus board
The pcb layout

Programming the board

In order to make the PCB layout as simple as possible and to add some fun to the programming, the LEDs are connected in a rather silly pattern. To light an LED one at a time beginning at the top and going around the circle to the right, you have to send the following pattern:

7  6  5  1  2  3  4  8

You may of course want to design your own PCB in a more logical fashion, in which case you will have to adapt the example program below.
The program animates a single LED going right and going left. It also simulates a pendulum and circulates a hole going right. Many other movements can of course be implemented, but hopefully the ones I supply will demonstrate the point.

As usual feel free to e-mail me if you have any problems.

The main workhorse in the program is the WriteAllDigital routine, which is called by

SYS USB_WriteAllDigital%,%nnnnnnnn

7 6 5 1 2 3 4 8 7


where %nnnnnnnn is any eight bit binary number. (In BBC BASIC the % sign in front of a number indicates that it has to be in binary notation). When this number is sent to the board, the states of the eight output lines will reflect this number. To light the LEDs connected to port 1 and port 8, for instance, you would write:

SYS USB_WriteAllDigital%,%10000001

Remember the LEDs are arranged as on the right:




As usual I supply a BBC BASIC for Windows program file as well as an executable file in case you don't have BB4W installed.

K8055_led_circus.zip

and here are the same two files for the K8061

K8051_led_circus.zip


10 REM LED_Circus
20 REM Version 1.0
30 REM Fool around with some LEDs
35 REM Jochen Lueg
40 REM Limavady, February 2011
50
60
70 PROCinit
80
90
100 W%=0
110 State$=" "
120 T%=10
130 SYS USB_OpenDevice%, 0
140 SYS USB_ClearAllDigital%
150 REMPROCflash_greeting
160
170 REM LED_right R LED left L
180 REM Crossover X Pendulum P
190 REM Hole right H Random A
200 REM Exit program S
210
220 PRINT "LED_right R LED left L"
230 PRINT "Crossover X Pendulum P"
240 PRINT "Random A Hole right H"
250 PRINT "Exit program S"
260
270
280 REPEAT
290 PROCcheck_key
300 IF State$="LED_right" PROCturn_right
310 IF State$="LED_left" PROCturn_left
320 IF State$="Crossover" PROCcross_over
330 IF State$="Pendulum" PROCpendulum
340 IF State$="Random" PROCrandom
350 IF State$="Hole_right" PROChole_right
360 IF State$="Bar_down" PROCbar_down
370 UNTIL INKEY(-82)
380 SYS USB_ClearAllDigital%
390 SYS USB_CloseDevice%
400 REPEAT UNTIL INKEY(0)=-1 : REM Clear keyboard buffer
410 END
420
430
440 DEFPROCbar_down
450 SYS USB_WriteAllDigital%,%01000000
460 TIME=0:REPEAT UNTIL TIME>T%*2
470 SYS USB_WriteAllDigital%,%10100000
480 TIME=0:REPEAT UNTIL TIME>T%*2
490 SYS USB_WriteAllDigital%,%00011000
500 TIME=0:REPEAT UNTIL TIME>T%*2
510 SYS USB_WriteAllDigital%,%00000101
520 TIME=0:REPEAT UNTIL TIME>T%*2
530 SYS USB_WriteAllDigital%,%00000010
540 TIME=0:REPEAT UNTIL TIME>T%*2
550 ENDPROC
560
570
580 DEFPROCrandom
590 LOCAL N%
600 N%=RND(8) -1
610 SYS USB_WriteAllDigital%,2^N%
620 TIME=0: REPEAT UNTIL TIME > T%
630 ENDPROC
640
650
660 DEFPROCcheck_key
670 IF INKEY(-52) State$="LED_right"
680 IF INKEY(-87) State$="LED_left"
690 IF INKEY(-67) State$="Crossover"
700 IF INKEY(-56) State$="Pendulum"
710 IF INKEY(-66) State$="Random"
720 IF INKEY(-85) State$="Hole_right"
730 IF INKEY(-101) State$="Bar_down"
740 REPEAT UNTIL INKEY(0)=-1
750 ENDPROC
760
770
780
790 DEFPROChole_right
800 SYS USB_WriteAllDigital%,%10011111
810 TIME=0:REPEAT UNTIL TIME>T%
820 SYS USB_WriteAllDigital%,%11001111
830 TIME=0:REPEAT UNTIL TIME>T%
840 SYS USB_WriteAllDigital%,%11101110
850 TIME=0:REPEAT UNTIL TIME>T%
860 SYS USB_WriteAllDigital%,%11111100
870 TIME=0:REPEAT UNTIL TIME>T%
880 SYS USB_WriteAllDigital%,%11111001
890 TIME=0:REPEAT UNTIL TIME>T%
900 SYS USB_WriteAllDigital%,%11110011
910 TIME=0:REPEAT UNTIL TIME>T%
920 SYS USB_WriteAllDigital%,%01110111
930 TIME=0:REPEAT UNTIL TIME>T%
940 SYS USB_WriteAllDigital%,%00111111
950 TIME=0:REPEAT UNTIL TIME>T%
960
970 ENDPROC
980
990
1000 DEFPROCpendulum
1010
1020 REM Right swing Ports 7 6 5 1 2 3 4 8
1030 SYS USB_WriteAllDigital%,%01000000
1040 TIME=0:REPEAT UNTIL TIME > T%*2
1050
1060 SYS USB_WriteAllDigital%,%00100000
1070 TIME=0:REPEAT UNTIL TIME > T%
1080
1090 SYS USB_WriteAllDigital%,%00010000
1100 TIME=0:REPEAT UNTIL TIME > T%
1110
1120 SYS USB_WriteAllDigital%,%00000001
1130 TIME=0:REPEAT UNTIL TIME > T%
1140
1150 SYS USB_WriteAllDigital%,%00000010
1160 TIME=0:REPEAT UNTIL TIME > T%
1170
1180 SYS USB_WriteAllDigital%,%00000100
1190 TIME=0:REPEAT UNTIL TIME > T%
1200
1210 SYS USB_WriteAllDigital%,%00001000
1220 TIME=0:REPEAT UNTIL TIME > T%
1230 SYS USB_WriteAllDigital%,%10000000
1240 TIME=0:REPEAT UNTIL TIME > T%
1250
1260 REM Left swing Ports 7 8 4 3 2 1 5 6
1270
1280 SYS USB_WriteAllDigital%,%01000000
1290 TIME=0:REPEAT UNTIL TIME > T%*2
1300
1310 SYS USB_WriteAllDigital%,%10000000
1320 TIME=0:REPEAT UNTIL TIME > T%
1330
1340 SYS USB_WriteAllDigital%,%00001000
1350 TIME=0:REPEAT UNTIL TIME > T%
1360
1370 SYS USB_WriteAllDigital%,%00000100
1380 TIME=0:REPEAT UNTIL TIME > T%
1390
1400 SYS USB_WriteAllDigital%,%0000010
1410 TIME=0:REPEAT UNTIL TIME > T%
1420
1430 SYS USB_WriteAllDigital%,%00000001
1440 TIME=0:REPEAT UNTIL TIME > T%
1450
1460 SYS USB_WriteAllDigital%,%00010000
1470 TIME=0:REPEAT UNTIL TIME > T%
1480 SYS USB_WriteAllDigital%,%00100000
1490 TIME=0:REPEAT UNTIL TIME > T%
1530 ENDPROC
1540
1550 REM Crossover Moves left and right at the same time
1560 REM Ports 7 86 45 31 2 31 45 86 7
1570 DEFPROCcross_over
1580 SYS USB_WriteAllDigital%,%01000000
1590 TIME=0:REPEAT UNTIL TIME > T%
1600 SYS USB_WriteAllDigital%,%10100000
1610 TIME=0:REPEAT UNTIL TIME > T%
1620 SYS USB_WriteAllDigital%,%00011000
1630 TIME=0:REPEAT UNTIL TIME > T%
1640 SYS USB_WriteAllDigital%,%00000101
1650 TIME=0:REPEAT UNTIL TIME > T%
1660 SYS USB_WriteAllDigital%,%00000010
1670 TIME=0:REPEAT UNTIL TIME > T%
1680 SYS USB_WriteAllDigital%,%00000101
1690 TIME=0:REPEAT UNTIL TIME > T%
1700 SYS USB_WriteAllDigital%,%00011000
1710 TIME=0:REPEAT UNTIL TIME > T%
1720 SYS USB_WriteAllDigital%,%10100000
1730 TIME=0:REPEAT UNTIL TIME > T%
1740 ENDPROC
1750
1760
1770 REM Turn right Ports 1 2 3 4 8 7 6 5
1780 DEFPROCturn_right
1790 SYS USB_WriteAllDigital%,%00000001
1800 TIME=0:REPEAT UNTIL TIME > T%
1810 SYS USB_WriteAllDigital%,%00000010
1820 TIME=0:REPEAT UNTIL TIME > T%
1830 SYS USB_WriteAllDigital%,%00000100
1840 TIME=0:REPEAT UNTIL TIME > T%
1850 SYS USB_WriteAllDigital%,%00001000
1860 TIME=0:REPEAT UNTIL TIME > T%
1870 SYS USB_WriteAllDigital%,%10000000
1880 TIME=0:REPEAT UNTIL TIME > T%
1890 SYS USB_WriteAllDigital%,%01000000
1900 TIME=0:REPEAT UNTIL TIME > T%
1910 SYS USB_WriteAllDigital%,%00100000
1920 TIME=0:REPEAT UNTIL TIME > T%
1930 SYS USB_WriteAllDigital%,%00010000
1940 TIME=0:REPEAT UNTIL TIME > T%
1950 ENDPROC
1960
1970
1980 REM Turm left 5 6 7 8 4 3 2 1
1990 DEFPROCturn_left
2000 SYS USB_WriteAllDigital%,%00010000
2010 TIME=0:REPEAT UNTIL TIME > T%
2020 SYS USB_WriteAllDigital%,%00100000
2030 TIME=0:REPEAT UNTIL TIME > T%
2040 SYS USB_WriteAllDigital%,%01000000
2050 TIME=0:REPEAT UNTIL TIME > T%
2060 SYS USB_WriteAllDigital%,%10000000
2070 TIME=0:REPEAT UNTIL TIME > T%
2080 SYS USB_WriteAllDigital%,%00001000
2090 TIME=0:REPEAT UNTIL TIME > T%
2100 SYS USB_WriteAllDigital%,%00000100
2110 TIME=0:REPEAT UNTIL TIME > T%
2120 SYS USB_WriteAllDigital%,%00000010
2130 TIME=0:REPEAT UNTIL TIME > T%
2140 SYS USB_WriteAllDigital%,%00000001
2150 TIME=0:REPEAT UNTIL TIME > T%
2160 ENDPROC
2170
2180
2190
2200 DEFPROCflash_greeting
2210 SYS USB_SetAllDigital%
2220 TIME = 0: REPEAT UNTIL TIME > 20
2230 SYS USB_ClearAllDigital%
2240 TIME = 0: REPEAT UNTIL TIME > 20
2250
2260 SYS USB_SetAllDigital%
2270 TIME = 0: REPEAT UNTIL TIME > 20
2280 SYS USB_ClearAllDigital%
2290 TIME = 0: REPEAT UNTIL TIME > 20
2300
2310 SYS USB_SetAllDigital%
2320 TIME = 0: REPEAT UNTIL TIME > 20
2330 SYS USB_ClearAllDigital%
2340 TIME = 0: REPEAT UNTIL TIME > 20
2350
2360 SYS USB_SetAllDigital%
2370 TIME = 0: REPEAT UNTIL TIME > 50
2380 SYS USB_ClearAllDigital%
2390 TIME = 0: REPEAT UNTIL TIME > 50
2400
2410 SYS USB_SetAllDigital%
2420 TIME = 0: REPEAT UNTIL TIME > 50
2430 SYS USB_ClearAllDigital%
2440 TIME = 0: REPEAT UNTIL TIME > 50
2450
2460 SYS USB_SetAllDigital%
2470 TIME = 0: REPEAT UNTIL TIME > 50
2480 SYS USB_ClearAllDigital%
2490 TIME = 0: REPEAT UNTIL TIME > 50
2500
2510 SYS USB_SetAllDigital%
2520 TIME = 0: REPEAT UNTIL TIME > 20
2530 SYS USB_ClearAllDigital%
2540 TIME = 0: REPEAT UNTIL TIME > 20
2550 SYS USB_SetAllDigital%
2560 TIME = 0: REPEAT UNTIL TIME > 20
2570 SYS USB_ClearAllDigital%
2580 TIME = 0: REPEAT UNTIL TIME > 20
2590 SYS USB_SetAllDigital%
2600 TIME = 0: REPEAT UNTIL TIME > 20
2610 SYS USB_ClearAllDigital%
2620 TIME = 0: REPEAT UNTIL TIME > 20
2630 ENDPROC
2640
2650
2660 DEFPROCinit
2670 REM Typing errors in routine name do not generate
REM an error message - they just hang up the program.
2680 SYS"LoadLibrary","K8055D.dll" TO USB_Board%
2690 SYS"GetProcAddress",USB_Board%,"OpenDevice" TO USB_OpenDevice%
2700 SYS"GetProcAddress",USB_Board%,"ReadAnalogueChannel",1 TO USB_ReadAnalogue%
2710 SYS"GetProcAddress",USB_Board%,"SetAllDigital" TO USB_SetAllDigital%
2720 SYS"GetProcAddress",USB_Board%,"CloseDevice" TO USB_CloseDevice%
2730 SYS"GetProcAddress",USB_Board%,"ClearAllDigital" TO USB_ClearAllDigital%
2740 SYS"GetProcAddress",USB_Board%,"ClearDigitalChannel" TO USB_ClearDigitalChannel%
2750 SYS"GetProcAddress",USB_Board%,"SetDigitalChannel" TO USB_SetDigitalChannel%
2760 SYS"GetProcAddress",USB_Board%,"WriteAllDigital" TO USB_WriteAllDigital%
2770 ENDPROC
2780
2790




Return to the interfacing index


Back to the Limavady home page

Tudor with sign