10
20 REM Lightseeker
30 REM Version 2.0
40 REM Point towards the light
50 REM Jochen Lueg
60 REM Limavady, January 2012
70
80
90 PROCK8055_init
100 SYS K8055_CloseDevice%
110 SYS K8055_OpenDevice%,0
120 ON ERROR PRINT REPORT$;" ";ERL :SYS
K8055_ClearAllDigital%:SYS K8055_CloseDevice%:STOP
130 PROCinit
140 COLOUR 128
150 CLS
160 COLOUR15
170 REM
180 REM Digital output 5 for On/Off, 6 for left right
190 REM Digital input 5 pulses as motor turns
200 REM
210 REM Analogue 1 bright =
0 dark = 200
220 PRINT
230 PRINT
240 PRINT" 1 ............... Left"
250 PRINT" 2 ............... Right"
260 PRINT" 3 ............... Stop"
270 PRINT
280 PRINT" C ............... Reset
counter"
290 PRINT" A ............... Search
light"
300 PRINT
310 PRINT" S ............... Leave
program"
320
330
340 REPEAT
350 K$=INKEY$(0)
360 IF K$="C" OR K$="c" Count%=0
370 IF K$="1" PROCturn_motor(1)
380 IF K$="2" PROCturn_motor(2)
390 IF K$="3" PROCturn_motor(0)
400 IF K$="a" OR K$="a" PROCauto
410 PROCread_ports
420 UNTIL K$="S" OR K$="s"
430
440 SYS K8055_ClearAllDigital%
450 SYS K8055_CloseDevice%
460 END
470
480
490 DEFPROCturn_motor(m%)
500
510 IF m%=1 THEN
520 SYS K8055_SetDigitalChannel%,5
530 SYS K8055_ClearDigitalChannel%,6
540 PRINTTAB(2,13)"Motor turning left "
550 M$="left"
560 ENDIF
570
580 IF m%=2 THEN
590 SYS K8055_SetDigitalChannel%,5
600 SYS K8055_SetDigitalChannel%,6
610 PRINTTAB(2,13)"Motor turning right"
620 M$="right"
630 ENDIF
640
650 IF m%=0 THEN
660 SYS K8055_ClearDigitalChannel%,5
670 SYS K8055_ClearDigitalChannel%,6
680 PRINTTAB(2,13)"Motor
stopped "
690 M$="stop"
700 ENDIF
710
720 ENDPROC
730
740
|
750 DEFPROCread_ports
760 SYS K8055_ReadDigitalChannel%,1 TO Pulse%
770 IF Pulse%=1 AND Flag%=0 THEN
780 IF M$="right" Count%+=1:Flag%=1
790 IF M$="left" Count%-=1:Flag%=1
800 ENDIF
810 IF Pulse%=0 Flag%=0
820 SYS K8055_ReadAnalogueChannel%,1 TO Light%
830 PRINTTAB(2,15);Count%;"
";"
";Light%;" "
840 IF M$="right" AND Count%>40 Count%=0
850 IF M$="left" AND Count%<0 Count%=40
860 ENDPROC
870
880
890 DEFPROCauto
900 LOCAL Bright%,Pos%
910 Bright%=255
920 Count%=0
930 PROCturn_motor(2)
940
950 REPEAT
960 PROCread_ports
970 IF Light%<Bright%
Bright%=Light%:Pos%=Count%
980 UNTIL Count%>39
990 PROCturn_motor(0)
1000 IF Count%<>Pos% THEN
1010 PROCturn_motor(1)
1020 REPEAT
1030 PROCread_ports
1040 UNTIL Count%=Pos%
1050 PROCturn_motor(0)
1060 ENDIF
1070 ENDPROC
1080
1090
1100 DEFPROCinit
1110 SYS K8055_ClearAllDigital%
1120 M$="stop"
1130 Count%=0
1140 Flag%=0
1150 ENDPROC
1160
1170
1180 DEFPROCK8055_init
1190 REM Typing errors in routine name do not
generate an error message - they just hang up the program.
1200 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
1210 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO
K8055_OpenDevice%
1220 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO
K8055_ReadAnalogueChannel%
1230
SYS"GetProcAddress",K8055_Board%,"SetAllDigital" TO
K8055_SetAllDigital%
1240 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO
K8055_CloseDevice%
1250 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO
K8055_ClearAllDigital%
1260 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel"
TO K8055_ClearDigitalChannel%
1270 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO
K8055_SetDigitalChannel%
1280 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel"
TO K8055_OutputAnalogChannel%
1290 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO
K8055_ClearAnalogChannel%
1300 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO
K8055_ClearAllAnalog%
1310 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO
K8055_WriteAllDigital%
1320 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO
K8055_ReadDigitalChannel%
1330 ENDPROC
1340
|