AndrewMascolo / CountUpDownTimer

MIT License
28 stars 20 forks source link

how to use with sprintf() function. #18

Closed msh2050 closed 7 years ago

msh2050 commented 7 years ago

it is noted in the examples :

// This DOES NOT format the time to 0:0x when seconds is less than 10.

// if you need to format the time to standard format, use the sprintf() function.

please any example or hint

AndrewMascolo commented 7 years ago

void setup() { Serial.begin(9600);

char buffer = "H:xx M:xx S:xx"; // something that will hold the modified string. char buffer[15]; works too but make sure it has enough room to hold all the visible characters plus the (carriage return / new line character) '\n'.

int hours = 12; int minutes = 35; int seconds = 40; sprintf(buffer, "H:%02d M:%02d S:%02d", hours, minutes, seconds); // %02d means you want to occupy 2 spaces with the character '0'. ie. H:00. "d" means the variable you are passing it will be a number.

Serial.println(buffer); // this should print out H:12 M:35 S:40 }

msh2050 commented 7 years ago

thanks alot 👍