arduinoarduino-ide

How can I print the status of an I/O port in Arduino?


I want to see the status of the port, but the following code gives me an error.

int PIN25_state = digitalRead(25);  // Read PIN25
Serial.println("PIN25_state: ", PIN25_state);

The error I get is

no matching function for call to 'println(const char [14], int&)'


Solution

  • Refer to the Serial.print() documentation. The parameters of the function print() is the same as println().

    Where the first argument is what you want to send through the serial port, and the second argument is the format like HEX, BIN, DEC, etc...

    So what you are doing is wrong.

    You should instead do:

    int PIN25_state = digitalRead(25);  // Read PIN25
    Serial.print("PIN25_state: ");
    Serial.println(PIN25_state);
    

    where print() will put the value in the same line without new line and println() will make it print and then go to new line.