-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestBrightSensor.h
74 lines (61 loc) · 1.74 KB
/
testBrightSensor.h
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
/*
*
*/
#ifndef TESTBRIGHTSENSOR_H
#define TESTBRIGHTSENSOR_H
#include <Arduino.h>
#include "brightSensor.h"
#include "driveControl.h"
extern uint32_t MILLIS;
const int sensorPin = 7;
const int ledPin = 4;
const int mtrLeftFwdPin = 9;
const int mtrLeftRevPin = 10;
const int mtrRightFwdPin = 5;
const int mtrRightRevPin = 6;
const float mtrLeftScale = 1.0;
const float mtrRightScale = 1.0;
brightSensor lightFollow(sensorPin, ledPin);
driveControl botDrive(mtrLeftFwdPin, mtrLeftRevPin, mtrLeftScale,
mtrRightFwdPin, mtrRightRevPin, mtrRightScale);
/*
*
*/
void testBrightSensor() {
static int state = 0;
lightFollow.loop();
botDrive.loop();
switch (state) {
/* Search by turning left */
case 0:
Serial.println("state 0");
if (lightFollow.getState()) {
Serial.println("Found Light");
botDrive.halt();
state = 1;
} if (botDrive.getIsIdle()) {
botDrive.turnLeft(500, 70);
}
break;
/* Go towards the light */
case 1:
Serial.println("state 1");
if (not lightFollow.getState()) {
botDrive.halt();
state = 2;
Serial.println("Switching to 2");
} if (botDrive.getIsIdle()) {
Serial.println("forward");
botDrive.forward(1000, 70);
}
break;
/* Search by turing slightly right then going to left state */
case 2:
Serial.println("state 2");
if (botDrive.getIsIdle()) {
botDrive.turnRight(500, 70);
state = 0;
}
} // switch
}
#endif