-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc_car.bs2
65 lines (56 loc) · 970 Bytes
/
rc_car.bs2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'{$STAMP BS2}
'{$PBASIC 2.5}
pulseCount VAR WORD
left VAR WORD
right VAR WORD
left = 0
right = 0
Main:
GOSUB Check_Buttons
PAUSE 50
GOSUB Assign_States
GOTO Main
END
'-------------------------------------
Check_Buttons:
IF (IN2 = 1 AND IN1 = 1) THEN
left = 1
right = 1
ELSEIF (IN2 = 1 AND IN1 = 0) THEN
left = 1
right = 0
ELSEIF (IN2 = 0 AND IN1 = 1) THEN
left = 0
right = 1
ENDIF
RETURN
Assign_States:
IF (left = 1 AND right = 1) THEN
GOSUB Stop_Pulse
ELSEIF (left = 1 AND right = 0) THEN
GOSUB Turn_Left
ELSEIF (left = 0 AND right = 1) THEN
GOSUB Turn_Right
ENDIF
RETURN
Stop_Pulse:
PULSOUT 13, 750
PULSOUT 12, 750
PAUSE 20
RETURN
Turn_Left:
DEBUG "Left", CR
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
DEBUG "Right", CR
FOR pulseCount = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN