Compare commits

...

2 Commits

Author SHA1 Message Date
BodgeMaster 579d28e34b removed bug notice since the issue resolved itself 2021-05-04 21:30:13 +02:00
BodgeMaster 5cc71d5ff5 finished implementation 2021-05-04 21:27:34 +02:00
1 changed files with 62 additions and 30 deletions

View File

@ -108,6 +108,7 @@ void runCommand(){
String mode; String mode;
uint8_t pin; uint8_t pin;
String state; String state;
uint8_t pwmState;
switch ((char)command) { switch ((char)command) {
case 'R': // run setup() again case 'R': // run setup() again
Serial.print("R"); Serial.print("R");
@ -194,35 +195,67 @@ void runCommand(){
Serial.print(analogRead(analogInputToDigitalPin(analogPin))); Serial.print(analogRead(analogInputToDigitalPin(analogPin)));
Serial.print("s"); Serial.print("s");
return; return;
case 'r': // read digital value case 'r': // read digital value
/*bug: Serial.print("r");
The following "r" (or any other text you may put there) will never get printed despite this code branch being executed. Dont ask me why or how. pin = waitForSerialInput(2).toInt();
Tested on Linux Mint 20.1, Arduino IDE version 2:1.0.5+dfsg2-4.1 if (pin >= NUM_DIGITAL_PINS) Serial.print("e");
Tested with Arduino Uno and Nano 328P else {
*/ Serial.print(digitalRead(pin));
Serial.print("r"); Serial.print("s");
pin = waitForSerialInput(2).toInt(); }
if (pin >= NUM_DIGITAL_PINS) Serial.print("e"); return;
else { case 'w': // write digital pin
Serial.print(digitalRead(pin)); Serial.print("w");
Serial.print("s"); pin = waitForSerialInput(2).toInt();
} state = waitForSerialInput(1);
return; if (pin >= NUM_DIGITAL_PINS) Serial.print("e");
case 'w': // write digital pin else if (state == "h") {
Serial.print("w"); digitalWrite(pin, HIGH);
pin = waitForSerialInput(2).toInt(); Serial.print("s");
state = waitForSerialInput(1); } else if (state == "l") {
if (pin >= NUM_DIGITAL_PINS) Serial.print("e"); digitalWrite(pin, LOW);
else if (state == "h") { Serial.print("s");
digitalWrite(pin, HIGH); } else {
Serial.print("s"); Serial.print("e");
} else if (state == "l") { }
digitalWrite(pin, LOW); return;
Serial.print("s"); case 'p': // set a pwm pin
} else { Serial.print("p");
Serial.print("e"); pin = waitForSerialInput(2).toInt();
} pwmState = waitForSerialInput(3).toInt();
return; if (digitalPinHasPWM(pin)) {
analogWrite(pin, pwmState);
Serial.print("s");
} else {
Serial.print("e");
}
return;
case 't': // toggle a pin
Serial.print("t");
if (toggleState(waitForSerialInput(2).toInt())==UNKNOWN_PIN) Serial.print("e");
else Serial.print("s");
return;
case 'l':
Serial.print("l");
state = waitForSerialInput(1);
if (state=="h") {
digitalWrite(LED_BUILTIN, HIGH);
Serial.print("s");
} else if (state=="l") {
digitalWrite(LED_BUILTIN, LOW);
Serial.print("s");
} else if (state=="t") {
toggleState(LED_BUILTIN);
Serial.print("s");
} else {
Serial.print("e");
}
return;
case 'q':
Serial.print("qs");
while (true) {
}
return;
default: default:
Serial.print("e"); Serial.print("e");
} }
@ -247,7 +280,6 @@ void setup(){
Serial.read(); Serial.read();
} }
Serial.print("s\r\n"); Serial.print("s\r\n");
// testing
} }
void loop(){ void loop(){