kyrpav
kyrpav

Reputation: 778

How to use serial print for Arduino

I want to use Serial.print() for Arduino projects. The specific problem is that I want to print two numbers separated by slash like this:

56 / 345

I could do

int x = 56;
int y = 345;
Serial.print(x);
Serial.print("/");
Serial.print(y);

Can I avoid the second serial print or give only one serial print? The API does not use printf().

Upvotes: 0

Views: 1561

Answers (1)

coledot
coledot

Reputation: 2786

You could do an sprintf() to a temporary string, then Serial.print() that:

char tmp[32];  
sprintf(tmp, "%d/%d", x, y);  
Serial.print(tmp);

Upvotes: 2

Related Questions