-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlebab.ino
41 lines (37 loc) · 884 Bytes
/
lebab.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
int myPins[] = {12, 11, 10, 9, 8, 7, 6, 5};
char indices[] = "12345678";
unsigned long timeNow = 0; // microsec
int duration = 5000; // microsec
long timeOn[] = {-duration, -duration, -duration, -duration, -duration, -duration, -duration, -duration};
void setup()
{
Serial.begin(9600);
for (int n = 0; n < 8; n++) {
pinMode(myPins[n], OUTPUT);
}
}
void loop()
{
timeNow = micros();
for (int n = 0; n < 8; n++) {
if (timeNow < (timeOn[n] + duration)) {
digitalWrite(myPins[n], 1);
} else {
digitalWrite(myPins[n], 0);
}
}
delayMicroseconds(5);
}
void serialEvent() {
timeNow = micros();
while (Serial.available()) {
char inChar = (char)Serial.read();
Serial.println(inChar);
for (int n = 0; n < 8; n++) {
if (inChar == indices[n]) {
timeOn[n] = timeNow;
Serial.println(timeNow);
}
}
}
}