-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.ino
More file actions
57 lines (51 loc) · 1.4 KB
/
helpers.ino
File metadata and controls
57 lines (51 loc) · 1.4 KB
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
void displayState() {
Serial.print("estado:");
Serial.println(state);
}
void counter(bool show) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillisDisplay >= 1000) {
previousMillisDisplay = currentMillis;
lastDigit--;
}
}
void redTrafficLight() {
digitalWrite(PIN_RED_LED, HIGH);
digitalWrite(PIN_GREEN_LED, LOW);
}
void greenTrafficLight(bool hurry) {
if(hurry) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillisGreenLight >= 500) {
previousMillisGreenLight = currentMillis;
lastGreenLight = !lastGreenLight;
digitalWrite(PIN_GREEN_LED, lastGreenLight);
}
} else {
digitalWrite(PIN_GREEN_LED, HIGH);
}
digitalWrite(PIN_RED_LED, LOW);
}
unsigned long previousMillisSound = 0;
void beep(bool hurry) {
unsigned long currentMillis = millis();
if(hurry) {
if (currentMillis - previousMillisSound >= 200) {
previousMillisSound = currentMillis;
tone(SOUND_PIN, 500, 50);
}
} else {
if (currentMillis - previousMillisSound >= 1000) {
previousMillisSound = currentMillis;
tone(SOUND_PIN, 1500, 100);
}
}
}
void closeBarrier(){
Serial.println("closeBarrier");
myservo.write(10);
}
void openBarrier(){
Serial.println("openBarrier");
myservo.write(80);
}