10 REM Light follower
20 REM For The Velleman K8055 USB interface
30 REM Play with tow LDRs and a stepper motor
40 REM Jochen Lueg
50 REM http://roevalley.com/newsbrowser/v-projects/v-index.htm
60 REM Version 1.1
70 REM February 2012
80
90 ON ERROR PRINT ERL;" ";REPORT$:END
100 PROCK8055_init
110 SYS K8055_CloseDevice%
120 SYS K8055_OpenDevice%,0
130 SYS K8055_ClearAllDigital%
140 PROCinit
150 PROCprintout
160
170 REM Main loop
180 REPEAT
190 Key$=INKEY$(0) : REPEAT UNTIL INKEY(0)=-1
200 IF Key$="a" OR Key$="A" PROCadjust
210 IF Key$="l" OR Key$="L" PROClight_levels
220 IF Key$="f" OR Key$="F" PROCfollow_light
230 IF Key$="s" OR Key$="S" PROCbright_spot
240 IF Key$="=" OR Key$="+" Dir$="Finished"
250 IF Key$="h" OR Key$="H" Dir$="Halt"
260 IF Key$="c" OR Key$="C" THEN
270 Coil%-=1:IF Coil%<1 Coil%=8
280 SYS K8055_WriteAllDigital%,HalfStep%(Coil%)
290 ENDIF
300 IF Key$="z" OR Key$="Z" THEN
310 Coil%+=1:IF Coil%>8 Coil%=1
320 SYS K8055_WriteAllDigital%,HalfStep%(Coil%)
330 ENDIF
340 UNTIL Dir$="Finished"
350
360 PRINTTAB(1,16)"All good things come to an
end.
"
370 SYS K8055_ClearAllDigital%
380 SYS K8055_CloseDevice%
390 REPEAT UNTIL INKEY(0)=-1 :REM Clear keyboard buffer
400 END
410
420
430 DEFPROCbright_spot
440 LOCAL Bright%,B%
450 Turn%=0
460 Bright%=0
470 FOR J%=1 TO 400
480 SYS K8055_ReadAnalogChannel%,1 TO ADC1%
490 SYS K8055_ReadAnalogChannel%,2 TO ADC2%
500 B%=ADC1%+ADC2%
510 IF Bright%<B% Bright%=B%:Turn%=J%
520 Coil%+=1: IF Coil%>8 Coil%=1
530 SYS K8055_WriteAllDigital%,HalfStep%(Coil%)
540 NEXT
550 FOR J%=1 TO Turn%
560 Coil%-=1:IF Coil%<1 Coil%=8
570 SYS K8055_WriteAllDigital%,HalfStep%(Coil%)
580 NEXT
590 SYS K8055_ClearAllDigital%
600 ENDPROC
610
620 DEFPROCfollow_light
630 Turn%=0
640 Rot%=0
650 ADC1%=0
660 ADC2%=0
670 REPEAT
680 SYS K8055_ReadAnalogChannel%,1 TO ADC1%
690 SYS K8055_ReadAnalogChannel%,2 TO ADC2%
700 IF ADC1%<ADC2%+3 AND ADC1%<ADC2%-3 THEN
710 Turn%-=1
720 Coil%-=1 :IF Coil%<1 Coil%=8
730 SYS K8055_WriteAllDigital%,HalfStep%(Coil%)
740 Key$=INKEY$(0)
750 ENDIF
760 IF ADC2%<ADC1%-3 AND ADC2%<ADC1%+3 THEN
770 Turn%+=1
780 Coil%+=1 :IF Coil%>8 Coil%=1
790 SYS K8055_WriteAllDigital%,HalfStep%(Coil%)
800 Key$=INKEY$(0)
810 ENDIF
820 UNTIL Key$="h" OR Key$="H"
830
840 SYS K8055_ClearAllDigital%
850 ENDPROC
860
870
880 DEFPROCadjust
890 CLS
900 REPEAT
910 SYS K8055_ReadAnalogChannel%,1 TO ADC1%
920 SYS K8055_ReadAnalogChannel%,2 TO ADC2%
930 PRINTTAB(1,2) ADC1%,ADC2%
940 PRINTTAB(1,4)"Press 'H' to return to the menu"
950 Key$=INKEY$(10) : REPEAT UNTIL INKEY(0)=-1
960 UNTIL Key$="h" OR Key$="H"
970 PROCprintout
980 ENDPROC
990
1000
|
1010 DEFPROClight_levels
1020 Coil%=1
1030 Turn%=0
1040 ADC1%=0
1050 ADC2=0
1060 CLS
1070 REPEAT
1080 SYS K8055_WriteAllDigital%,HalfStep%(Coil%): FOR I%=1 TO T%:NEXT
1090 Turn%+=1
1100 Coil%+=1:IF Coil%>8 Coil%=1
1110 SYS K8055_ReadAnalogChannel%,1 TO ADC1%
1120 SYS K8055_ReadAnalogChannel%,2 TO ADC2%
1130 PRINT;ADC1%;" ";ADC2%;" ";
1140 UNTIL Turn%=400
1150 SYS K8055_ClearAllDigital%
1160 PRINT
1170 PRINT
1180 PRINT" Press 'H' to return to the menu"
1190 REPEAT
1200 Key$=INKEY$(20) : REPEAT UNTIL INKEY(0)=-1
1210 UNTIL Key$="h" OR Key$="H"
1220 PROCprintout
1230 ENDPROC
1250
1260 DEFPROCprintout
1270 CLS
1280 PRINT "You can do the following:"
1290 PRINT
1300 PRINT " Adjust input voltages . . . . . . A"
1310 PRINT " Check light levels . . . . . . L"
1320 PRINT " Find the brightest spot . . . . . . S"
1330
1340 PRINT " Follow light . . . . . . F"
1350 PRINT " Turn
left
. . . . . . Z"
1360 PRINT " Turn
right
. . . . . . C"
1370 PRINT
1380 PRINT " Return to menu . . . . . . H"
1390 PRINT " Leave the program . . . . . . ="
1400 ENDPROC
1410
1420
1430
1440
1450 DEFPROCinit
1460 COLOUR 128
1470 CLS
1480 COLOUR 15
1490 Coil%=1: REM Current operational stepper motor coil
1500 Turn%=0: REM Position within 1 revolution %0 is one complete turn
1510 Dir$="Halt"
1520
1530 DIM HalfStep%(8)
1540 HalfStep%(1)=%00000011
1550 HalfStep%(2)=%00001111
1560 HalfStep%(3)=%00001100
1570 HalfStep%(4)=%00111100
1580 HalfStep%(5)=%00110000
1590 HalfStep%(6)=%11110000
1600 HalfStep%(7)=%11000000
1610 HalfStep%(8)=%11000011
1620
1630 DIM FullStep%(4)
1640 FullStep%(1)=%00000011
1650 FullStep%(2)=%00001100
1660 FullStep%(3)=%00110000
1670 FullStep%(4)=%11000000
1680 FOR J%=1 TO 4
1690 SYS K8055_WriteAllDigital%,FullStep%(J%)
1700 NEXT
1710 SYS K8055_ClearAllDigital%
1720 ENDPROC
1730
1740
1750 DEFPROCK8055_init
1760 REM Typing errors in routine name do not generate an error message - they just hang up the program.
1770 REM These are all the system calls in the order found in the manual
1780 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
1790 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
1800 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
1810 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogChannel%
1820 SYS"GetProcAddress",K8055_Board%,"ReadAllAnalog" TO K8055_ReadAllAnalog%
1830 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
1840 SYS"GetProcAddress",K8055_Board%,"OutputAllAnalog" TO K8055_OutputAllAnalog%
1850 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
1860 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog
1870 SYS"GetProcAddress",K8055_Board%,"SetAnalogChannel" TO K8055_SetAnalogChannel%
1880 SYS"GetProcAddress",K8055_Board%,"SetAllAnalog" TO K8055_SetAllAnalog%
1890 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
1900 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
1910 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
1920 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
1930 SYS"GetProcAddress",K8055_Board%,"SetAllDigital" TO K8055_SetAllDigital%
1940 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
1950 SYS"GetProcAddress",K8055_Board%,"ReadAllDigital" TO K8055_ReadAllDigital%
1960 SYS"GetProcAddress",K8055_Board%,"ResetCounter" TO K8055_ResetCounter%
1970 SYS"GetProcAddress",K8055_Board%,"ReadCounter" TO K8055_ReadCounter%
1980 SYS"GetProcAddress",K8055_Board%,"SedtCounterDebouceTime" TO K8055_SetCounterDebounceTime%
1990 ENDPROC
|