Compare commits

..

No commits in common. "579d28e34b56736da57a5a7f888780b95c20224c" and "5a82d0d9889a7edf28808b3638a8b4925f6107cc" have entirely different histories.

1 changed files with 30 additions and 62 deletions

View File

@ -108,7 +108,6 @@ 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");
@ -195,67 +194,35 @@ 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
Serial.print("r"); /*bug:
pin = waitForSerialInput(2).toInt(); 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.
if (pin >= NUM_DIGITAL_PINS) Serial.print("e"); Tested on Linux Mint 20.1, Arduino IDE version 2:1.0.5+dfsg2-4.1
else { Tested with Arduino Uno and Nano 328P
Serial.print(digitalRead(pin)); */
Serial.print("s"); Serial.print("r");
} pin = waitForSerialInput(2).toInt();
return; if (pin >= NUM_DIGITAL_PINS) Serial.print("e");
case 'w': // write digital pin else {
Serial.print("w"); Serial.print(digitalRead(pin));
pin = waitForSerialInput(2).toInt(); Serial.print("s");
state = waitForSerialInput(1); }
if (pin >= NUM_DIGITAL_PINS) Serial.print("e"); return;
else if (state == "h") { case 'w': // write digital pin
digitalWrite(pin, HIGH); Serial.print("w");
Serial.print("s"); pin = waitForSerialInput(2).toInt();
} else if (state == "l") { state = waitForSerialInput(1);
digitalWrite(pin, LOW); if (pin >= NUM_DIGITAL_PINS) Serial.print("e");
Serial.print("s"); else if (state == "h") {
} else { digitalWrite(pin, HIGH);
Serial.print("e"); Serial.print("s");
} } else if (state == "l") {
return; digitalWrite(pin, LOW);
case 'p': // set a pwm pin Serial.print("s");
Serial.print("p"); } else {
pin = waitForSerialInput(2).toInt(); Serial.print("e");
pwmState = waitForSerialInput(3).toInt(); }
if (digitalPinHasPWM(pin)) { return;
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");
} }
@ -280,6 +247,7 @@ void setup(){
Serial.read(); Serial.read();
} }
Serial.print("s\r\n"); Serial.print("s\r\n");
// testing
} }
void loop(){ void loop(){