Why am I not getting the letter "P" on the serial monitor, instead I am getting 80 which is ascii for letter "P" ??
can anybody help.
Thanks
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte ampm;
ampm ='P';
Serial.println(ampm);
}
Why am I not getting the letter "P" on the serial monitor, instead I am getting 80 which is ascii for letter "P" ??
can anybody help.
Thanks
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte ampm;
ampm ='P';
Serial.println(ampm);
}
Try double quotes?
ampm ="P";
Or char ampm = 'P';
Interesting, three of four methods apparently send the byte representing the "P", and one method sends the decimal representation of the byte representing the "P".
void setup()
{
Serial.begin(9600);
}
void loop()
{
//char ampm;
byte ampm;
ampm ='P';
Serial.print(ampm);
//Serial.write(ampm);
Serial.println();
}
Thank your for your suggestions, I changed my code and it works now.
if (ampm ==1)
{
Serial.print("PM");
}
else
{
Serial.print("AM");
}
If you maintain a boolean variable true if PM false if AM then you could use the ternary operator.
boolean pm = true;
Serial.print( pm ? "PM" : "AM" ); // will print PM in this case
That is a functional equivalent to :
if (ampm ==1)
{
Serial.print("PM");
}
else
{
Serial.print("AM");
}
Maybe:
void setup()
{
Serial.begin(9600);
}
void loop()
{
byte ampm;
ampm ='P';
Serial.println( (char) ampm);
}