-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduinoCode.cpp
More file actions
62 lines (50 loc) · 1.18 KB
/
ArduinoCode.cpp
File metadata and controls
62 lines (50 loc) · 1.18 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
58
59
60
61
62
unsigned long previousMillis = 0;
unsigned long interval = 1000;
bool LED_BLINK = false;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
while( Serial.available() ){
char command = Serial.read();
switch(command){
case 'a':
digitalWrite(LED, LOW);
break;
case 'A':
digitalWrite(LED, HIGH);
break;
case 'b':
digitalWrite(LED, LOW);
LED_BLINK = false;
break ;
case 'B':
LED_BLINK = true;
break;
case 'c':
digitalWrite(LED, LOW);
LED_BLINK = false;
interval = 1000;
break ;
case 'C':
LED_BLINK = true;
interval = 200;
break;
default:
Serial.println("Unknown command");
break;
}
}
if ( LED_BLINK ){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (digitalRead(LED) == LOW) {
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
}
}
}