-
Notifications
You must be signed in to change notification settings - Fork 1
/
sensors.cpp
79 lines (61 loc) · 1.67 KB
/
sensors.cpp
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
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "defines.h"
void sensorSetup() {
digitalWrite(WALL_SENSOR,HIGH); //Pull up the wall sensor to be on by default...
digitalWrite(TOKENS_LOADED,HIGH); //Pull up token toggle
}
char testWallSensor(void) {
return digitalRead(WALL_SENSOR) == LOW;
}
char testTokensLoadedSensor(void) {
return digitalRead(TOKENS_LOADED) == LOW;
}
void readFrontSensors(int values[]) {
values[0] = analogRead(TAPE_SENSOR_FRONT_LEFT);
values[1] = analogRead(TAPE_SENSOR_FRONT_CENTER);
values[2] = analogRead(TAPE_SENSOR_FRONT_RIGHT);
}
void readBackSensors(int values[]) {
values[0] = analogRead(TAPE_SENSOR_REAR_LEFT);
values[1] = analogRead(TAPE_SENSOR_REAR_CENTER);
values[2] = analogRead(TAPE_SENSOR_REAR_RIGHT);
}
char readSideSensor() {
return digitalRead(TAPE_SENSOR_SIDE) == LOW;
}
char readHomeBeacon() {
return digitalRead(HOME_BEACON_SENSOR) == LOW;
}
char readFrontSeesaw() {
return digitalRead(FRONT_SEESAW_SENSOR) == LOW;
}
char readSideSeesaw() {
return digitalRead(SIDE_SEESAW_SENSOR) == LOW;
}
int removeMin(int val[]) {
int min = val[0];
if (val[1] < min)
min = val[1];
if (val[2] < min)
min = val[2];
val[0] -= min;
val[1] -= min;
val[2] -= min;
return min;
}
int getLinePos(int val[]) {
int num = -val[0] + val[2];
long denom = val[0] + val[1] + val[2];
return (int)(((long)num * LINE_POS_SCALE) / denom);
}
char hasLine(int rawVal[]) {
if (rawVal[0] > LINE_SENSOR_MIN_THRES
|| rawVal[1] > LINE_SENSOR_MIN_THRES
|| rawVal[2] > LINE_SENSOR_MIN_THRES)
return 1;
return 0;
}