-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.ino
66 lines (54 loc) · 1.15 KB
/
robot.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
#include <Arduino.h>
#include <component/Lcd.h>
#include <controller/WiFi.h>
#include <strategy/FactoryStrategy.h>
#include "controller/SerialController.h"
#include "component/SonarSensor.h"
#include "ActionList.h"
#define LCD 0
#define SERIAL_CONTROLLER 0
#if SERIAL_CONTROLLER
SerialController controller;
#endif
#define PORT_CONTACTSENSORS 2
#ifdef PROTOTYPE
SonarSensor frontLeftSensor { 11, 10 };
#endif
volatile bool hitObstacle = false;
void setup() {
lcdSetup();
i2cSetup();
attachInterrupt(digitalPinToInterrupt(PORT_CONTACTSENSORS), interrupt, CHANGE);
Serial.begin(9600);
changeStrategy(&factoryStrategy);
#ifdef PROTOTYPE
changeStrategy(&wifiStrategy);
#endif
}
void loop() {
#if SERIAL_CONTROLLER
controller.checkController();
#endif
if (hitObstacle) {
activeStrategy->obstacleFound();
} else {
activeStrategy->run();
}
actionList.playNextAction();
#ifdef PROTOTYPE
if (!hitObstacle) {
frontLeftSensor.scan();
if (frontLeftSensor.isInRange(15)) {
hitObstacle = true;
}
}
#endif
}
void interrupt() {
int state = digitalRead(PORT_CONTACTSENSORS);
if (state == LOW) {
hitObstacle = true;
} else {
hitObstacle = false;
}
}