forked from MeowLaboratories/sumo-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor_update.ino
87 lines (69 loc) · 1.82 KB
/
sensor_update.ino
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
84
85
86
87
void status_update()
{
int thres = 200;
//ir prox
if(((analogRead(FrontLeft_prox_pin)+analogRead(FrontLeft_prox_pin)+analogRead(FrontLeft_prox_pin))/3) > thres)
FL_prox = 1;
else
FL_prox = 0;
if(((analogRead(FrontRight_prox_pin) + analogRead(FrontRight_prox_pin) + analogRead(FrontRight_prox_pin) )/3) > thres)
FR_prox = 1;
else
FR_prox = 0;
if(((analogRead(right_prox_pin)+analogRead(right_prox_pin)+analogRead(right_prox_pin))/3) > thres)
right_prox = 1;
else
right_prox = 0;
if(((analogRead(left_prox_pin)+analogRead(left_prox_pin)+analogRead(left_prox_pin))/3) > thres)
left_prox = 1;
else
left_prox = 0;
if(((analogRead(mid_prox_pin)+analogRead(mid_prox_pin)+analogRead(mid_prox_pin))/3) > thres)
mid_prox = 1;
else
mid_prox = 0;
//line sensor
if(analogRead(left_ir_pin) > L_thres) left_ir = 1;
else
left_ir = 0;
if(analogRead(right_ir_pin) > R_thres) right_ir = 1;
else
right_ir = 0;
FRONT = FL_prox*4 + mid_prox*2 + FR_prox;
LINE = left_ir*2 + right_ir;
}
int read_env()
{
if(FRONT == 0b000 && prev == 1)
{
return 150;
}
if(FRONT == 0b000 && prev == -1)
{
return -150;
}
if(FRONT == 0b001)
{
prev = 1;
return 100;
}
if(FRONT == 0b011)
{
prev = 1;
return 50;
}
if(FRONT == 0b101 || FRONT == 0b010 || FRONT == 0b111)
{
return 0;
}
if(FRONT == 0b110)
{
prev = -1;
return -50;
}
if(FRONT == 0b100)
{
prev = -1;
return -100;
}
}