-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathardunio.ino
38 lines (35 loc) · 944 Bytes
/
ardunio.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
// Maximum GPIO pin number
#define MAX_PIN 13
// Times to reset the GPIO value (INPUT)
unsigned long reset[MAX_PIN+1];
void setup() {
// Reset the initial values for all pins
for (int pin = 0; pin <= MAX_PIN; pin++) {
pinMode(pin, INPUT);
reset[pin] = 0;
}
// Setup the serial communication
Serial.begin(115200);
Serial.setTimeout(1);
// Make sure millis() isn't 0
delay(1);
}
void loop() {
unsigned long current = millis();
// If there's (at least) a pending byte, read it
if (Serial.available() > 0) {
byte pin = Serial.read();
if (pin <= MAX_PIN) {
// The pin should be reset back to INPUT after 10 milliseconds
pinMode(pin, OUTPUT);
reset[pin] = current + 10;
}
}
// Check any pins have surpassed the reset time
for (int pin = 0; pin <= MAX_PIN; pin++) {
if (reset[pin] < current && reset[pin] != 0) {
pinMode(pin, INPUT);
reset[pin] = 0;
}
}
}