-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcCarTest2.spin
85 lines (60 loc) · 1.28 KB
/
rcCarTest2.spin
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
72
73
74
75
76
77
78
79
80
81
82
83
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
moveEnable=8
steerEnable=13
forward=10
backward=9
left=12
right=11
adc_clk=14
adc_dout=15
adc_din=16
adc_cs=17
num_channels=8
act_channels=8
resolution=12
adc_mode=1
OBJ
car: "rcCar"
adc: "ADC_INPUT_DRIVER"
pst: "Parallax Serial Terminal"
VAR
long adcState[8]
long adcMax[8]
long adcMin[8]
long adcVal[8]
CON
carSpeed=3
steerSpeed=8
PUB rcCarTest | fStart
dira[18..23]~~
adc.start_pointed(adc_din,adc_dout,adc_clk,adc_cs,num_channels,act_channels,resolution,adc_mode,false,@adcState,@adcVal,@adcMax,@adcMin)
car.start(moveEnable,forward,backward,steerEnable,left,right,true)
pst.start(115200)
car.setSpeed(carSpeed)
car.setSteerSpeed(steerSpeed)
repeat
outa[18]~~
outa[20]~
car.stop
waitcnt(cnt+clkfreq)
outa[19]~~
car.center
car.forward
fstart:=cnt
repeat while adcVal[4]<1000
pst.dec(adcVal[4])
pst.NewLine
if cnt-fStart>clkfreq>>1
outa[18]~
car.setSpeed(1)
car.stop
outa[19]~
waitcnt(cnt+clkfreq<<1)
outa[20]~~
car.left
waitcnt(cnt+clkfreq>>2)
car.setSpeed(carSpeed)
car.backward
waitcnt(cnt+clkfreq)