-
Notifications
You must be signed in to change notification settings - Fork 0
/
midterm2_q2.bs2
71 lines (64 loc) · 972 Bytes
/
midterm2_q2.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
66
67
68
69
70
71
'{$STAMP BS2}
'{$PBASIC 2.5}
Setup:
tau VAR WORD
counter VAR WORD
time VAR WORD
tau_threshold VAR WORD
Main:
tau_threshold = 200
time = 0
HIGH 8
'train stops for 5 seconds
FOR counter = 1 TO 100:
GOSUB Check_Tau
IF (tau > tau_threshold) THEN
GOSUB Passenger_Detected
ENDIF
PAUSE 47
NEXT
GOSUB No_Passenger_Detected
END
' stages ------------
Passenger_Detected:
DEBUG "passenger"
LOW 8
DO WHILE (IN1 = 0)
TOGGLE 11
PAUSE 50
LOOP
GOSUB No_Passenger_Detected
RETURN
No_Passenger_Detected:
DEBUG "no passenger", CR
time = 0
LOW 11
LOW 8
FOR counter = 1 TO 40:
TOGGLE 10
PAUSE 50
NEXT
GOSUB Forward
RETURN
Forward:
DEBUG "forward", CR
time = 0
LOW 10
LOW 11
FOR counter = 1 TO 150:
GOSUB Forward_Pulse
NEXT
END
RETURN
' subroutines --------
Check_Tau:
HIGH 0
PAUSE 3
RCTIME 0, 1, tau
DEBUG DEC tau, HOME, CR
RETURN
Forward_Pulse:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
RETURN