Newer
Older
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
88
#include "Scarabi.h"
Scarabi* Scarabi::_singleton = 0;
Scarabi* Scarabi::singleton()
{
if (_singleton==0)
_singleton = new Scarabi();
return _singleton;
}
Scarabi::Scarabi() : color(colorBlue), timerMatchStarted(0), isRunning(false)
{
Serial.println("Skarabi created !");
Serial.println("First it was Scarabi, but now it's Skarabi...");
Move::singleton();
pinMode(PIN_TIRETTE, INPUT);
matchTimeInfo = TIME_INFO;
}
Scarabi::~Scarabi()
{
//dtor
}
void Scarabi::update()
{
// Call in the loop function
currentTimer = micros();
if (isRunning)
{
if (currentTimer - timerMatchStarted >= TIME_MATCH - 1000000)
{
isRunning = false;
Move::singleton()->stop();
Serial.print("END OF THE MATCH !!!");
}
else
{
Move::singleton()->update(micros() - previousTimer);
if (currentTimer - timerMatchStarted >= matchTimeInfo - 1000)
{
Serial.print((TIME_MATCH - currentTimer + timerMatchStarted)/1000000);
Serial.print(" seconds left until the end of the match !\n");
matchTimeInfo += TIME_INFO;
}
}
}
previousTimer = micros();
}
void Scarabi::waitTirette(bool avoid)
{
Serial.println("Waiting for the tirette to be removed...");
// Waits for the tirette to be removed
bool tiretteWasPresent = false;
if (!avoid)
while(true)
{
if (digitalRead(PIN_TIRETTE)==LOW && tiretteWasPresent)
break;
if (digitalRead(PIN_TIRETTE)==HIGH)
tiretteWasPresent = true;
}
Serial.println("Tirette removed !");
// Beginning of the match timer
timerMatchStarted = micros();
isRunning = true;
// Departure area
if(digitalRead(PIN_COLOR)==HIGH)
color = colorBlue;
else
color = colorRed;
// Debug
//Move::singleton()->startAction(MOVE_FORWARD);
}
Scarabi::sideColor Scarabi::getColor()
{
return color;
}
void Scarabi::finalStop()
{
isRunning = false;
}