-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcCarTest.spin
81 lines (57 loc) · 1.21 KB
/
rcCarTest.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
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
if cnt-fStart>clkfreq
outa[18]~
car.setSpeed(4)
car.stop
outa[19]~
waitcnt(cnt+clkfreq<<1)
outa[20]~~
car.left
car.setSpeed(carSpeed)
car.backward
waitcnt(cnt+clkfreq)