-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.ino
37 lines (33 loc) · 848 Bytes
/
Main.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
const int blinkPin = 2;
const int motorPin = 13;
const int buzzerPin = 8;
long time;
void setup() {
pinMode(motorPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(blinkPin, INPUT);
digitalWrite(motorPin, HIGH);
Serial.begin(9600);
}
void loop() {
if (!digitalRead(blinkPin)) {
time = millis();
while (!digitalRead(blinkPin)) {
digitalWrite(buzzerPin, LOW);
digitalWrite(motorPin, LOW);
delay(1000);
}
Serial.println("Driver is AWAKE");
} else {
if (TimeDelay() >= 4000) // Adjusted the comparison value to milliseconds
{digitalWrite(buzzerPin, HIGH);
Serial.println("Driver is SLEEPING");
}
if (TimeDelay() >= 5000) // Adjusted the comparison value to milliseconds
digitalWrite(motorPin, HIGH);
}
}
int TimeDelay() {
long t = millis() - time;
return t;
}