Pages: [1]   Go Down
Author Topic: Samples in reference pages to print command  (Read 605 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the extended reference pages there is some sample code to show use of the print command which can be monitored at the console, this code takes an analogue input on analog input 0 and outputs the value to the console using the serial print command.

Here is the bit of code I am referring to...

 Serial.print("\t");                // print a tab character
  Serial.print(analogValue/4, BYTE); // print as a raw byte value (divide the
                                     // value by 4 because analogRead() returns numbers
                                     // from 0 to 1023, but a byte can only hold values
                                     // up to 255)
  Serial.print("\t");                // print a tab character  

My comment or question relates to the statement about the byte command only being able to show values up to 255 which I am OK with, however if you run this code the arduino will output 10 bits of data for the analogue read command and show the value all the way up to 1023.
So I guess my question is;... is the analogue read command a special case as it presents data in a 10 bit (2 byte)   format or have I misinterpreted the way this serial print command is working?  

thanks - belphit.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A byte can only go up to 255, but if you want to print bigger numbers (e.g. int's) you can print them as text (e.g. the four bytes ASCII '1' = 49, ASCII '0' = 48, ASCII '2' = 50, ASCII '3' = 51).  
Logged

Pages: [1]   Go Up
Jump to: