Skip to main content
edited tags
Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126
Source Link
Carrot M
  • 86
  • 1
  • 6

Sending Something to Serial and Writing it Returns a Correlated but Strange Number

I have an indescribable bug where read and write commands give back an array of numbers that are the digits of the input number except +48. Kinda hard to explain. Basically if I type 0 into this code:

    void setup(){
      Serial.begin(9600); //Begin serial connection
    }
    void loop(){
      if(Serial.available()){ //If serial available...
        double ser = Serial.read(); //Read serial value and write it to 'ser'
        Serial.println(ser); //Print 'ser'
      }
    }

I receive 48. 1 means 49, 2 means 50, 3 means 51... And then two digit numbers, which are the same except for each digit. 10 returns 49 48, 33 returns 51 51, 22 returns 50 50.