-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino_do.ino
64 lines (51 loc) · 1.27 KB
/
arduino_do.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
// yaqd-wright
// wright-arduino firmware 1.0
// Digital Write to pins 0-13 of Arduino Micro
// author: Kent Meyer 10/2024
// note that all pins are set to LOW on reset...this can be reconfigured if needed
const int numPins = 14;
const int defaultPinSetting = LOW;
void setup() {
for(int i=0; i<numPins; i++)
{
pinMode(i, OUTPUT);
digitalWrite(i,defaultPinSetting);
}
Serial.begin(9600);
}
void loop()
{
if (Serial.available()) serialEvent();
}
void serialEvent() { // occurs whenever new data comes in the hardware serial RX
int input_size=3;
int pin=0;
int setval=LOW;
char input[input_size] = {0};
char pins[1]={'0'};
char setting[1]={'0'};
byte size = Serial.readBytesUntil('\n', input, input_size);
char code=input[0];
pins[0]= input[1];
setting[0]=input[2];
//setval = atoi(setting);
if (setting[0] != '1') {
setval = LOW;
}
else {
setval = HIGH;
}
pin = int (strtol(pins, NULL, 16));
if (pin > (numPins-1)) {
Serial.println("INVALID PIN");
return;
}
if (code == 'M') {
digitalWrite(pin, setval);
}
else if (code == 'R') {
for(int i=0; i<numPins; i++) {
digitalWrite(i,defaultPinSetting);
}
}
}