2

I'm trying to perform a simple analogRead() and print out the result, as below:

void getVoltMeter() {

  readValue = analogRead(A2);
  readByte = readValue/4; 
  Serial.println(readValue);
  Serial.println(readByte);

}

But the output is:

023
255

The voltage input is 5V, so I would expect it to read:

1023
255

Why is the first digit being cut off?

7
  • 1
    What board are you using? – Majenko Aug 23 '17 at 21:02
  • What does it look like if you swap order of the println() commands? – jose can u c Aug 23 '17 at 21:07
  • What happens if you add a Serial.println() first? – Majenko Aug 23 '17 at 21:33
  • 1
    josecanuc: if I swap the print commands, it reads "4, 1024" @Majenko I'm using an Uno. If I put a blank print statement first, it prints the values as expected without truncation, so this is a solution. I mostly just want to understand what's going on that would make this happen. – janizer Aug 24 '17 at 17:17
  • 1
    In the serial monitor – janizer Aug 24 '17 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.