diff --git a/src/src.ino b/src/src.ino index 55c4216..cb8d898 100644 --- a/src/src.ino +++ b/src/src.ino @@ -48,7 +48,7 @@ void processCommand() { if (current_arg.equals("*IDN?")) { // CMD: *IDN? - Serial.print("SourceBots:Arduino:X:2.0\n"); + Serial.print("SourceBots:Arduino:X:2.1\n"); return; } @@ -125,6 +125,16 @@ void processCommand() { } else if (current_arg.equals("SET")) { getSlice(); + // Check if the pin is in the correct mode + int mode = getPinMode(pin); + if (mode != OUTPUT) { + if (mode == INPUT) { + Serial.print("NACK:Digital write is not supported in INPUT\n"); + } else { + Serial.print("NACK:Digital write is not supported in INPUT_PULLUP\n"); + } + return; + } if (current_arg.equals("1")) { // CMD: PIN::DIGITAL:SET:1 digitalWrite(pin, HIGH); @@ -144,6 +154,16 @@ void processCommand() { getSlice(); if (current_arg.equals("GET?")) { // CMD: PIN::ANALOG:GET? + // Check if the pin is in the correct mode + int mode = getPinMode(pin); + if (mode != INPUT) { + if (mode == OUTPUT) { + Serial.print("NACK:Analog read is not supported in OUTPUT\n"); + } else { + Serial.print("NACK:Analog read is not supported in INPUT_PULLUP\n"); + } + return; + } Serial.print(analogRead(pin)); Serial.print("\n"); return;