-
Notifications
You must be signed in to change notification settings - Fork 0
/
BOT_2.6.ino
120 lines (109 loc) · 2.73 KB
/
BOT_2.6.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int ledRdeca = 2;
int ledRumena = 3;
int ledZelena = 4;
int buzzer = 5;
int threshold = 300;
boolean L1;
boolean L2;
float checkTime;
float startTime;
float endTime;
bool ifFirst = 1;
bool ifFirstStart = 1;
float bestTime = 0;
float totalTime;
void setup() {
Serial.begin(9600);
pinMode(ledRdeca, OUTPUT);
pinMode(ledRumena, OUTPUT);
pinMode(ledZelena, OUTPUT);
pinMode(buzzer, OUTPUT);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Usmeri laserje");
while (analogRead(A2)<threshold && analogRead(A2)<threshold){
}
lcd.clear();
}
void loop() {
digitalWrite(ledRumena, LOW);
digitalWrite(ledRdeca, HIGH);
lcd.setCursor(0,0);
L1 = ifL1();
L2 = ifL2();
switch(L1){
case 1:
lcd.print("On your marks");
if (bestTime != 0){
lcd.setCursor(1,1);
lcd.print("Best: " + String((bestTime/1000),3) + "s");
}
ifFirst = 1;
break;
case 0:
switch(L2){
case 1:
digitalWrite(ledRumena, HIGH);
lcd.clear();
lcd.print("Get set");
if (bestTime != 0){
lcd.setCursor(1,1);
lcd.print("Best: " + String((bestTime/1000),3) + "s");
}
delay(200);
if (ifFirst == 1){
checkTime = millis();
ifFirst = 0;
}
if ((millis()-checkTime) >= 3000){
digitalWrite(ledRdeca, LOW);
digitalWrite(ledRumena, LOW);
digitalWrite(ledZelena, HIGH);
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(100); // ...for 1 sec
noTone(buzzer); // Stop sound...
lcd.clear();
lcd.print("Goooo");
startTime = millis();
delay(2000);
while (ifL2()){
}
digitalWrite(ledZelena, LOW);
endTime = millis();
totalTime = endTime-startTime;
lcd.clear();
lcd.print("Last lap:");
lcd.setCursor(1,1);
lcd.print(String((totalTime/1000),3)+"s");
if (bestTime == 0){
bestTime = totalTime;
} else if (totalTime < bestTime){
bestTime = totalTime;
}
delay(6000);
}
break;
case 0:
ifFirst=1;
//lcd.clear();
lcd.print("On your marks");
break;
}
break;
}
}
boolean ifL1() {
if (analogRead(A2)>threshold){
return(1);
} else { return(0); }
}
boolean ifL2() {
if (analogRead(A3)>threshold){
return(1);
} else { return(0); }
}