Arduino joining two int's -
hello have 2 variables timer1hh = 9 timer1mm = 7
i convert them strings, join them , "97" using code below:
string string1= string(timer1hh); string string2= string(timer1mm); string string3; string3=string1+string2; serial.println(string3);
thats fine want add leading 0 if below 10 like.
"0907"
so want able "if" between "0907" , "2034" type of thing. im totally blagged sprintf using "%02" , not working me.
any great.
pete
see sketch:
void setup() { int timer1hh = 9, timer1mm = 7; serial.begin(9600); //string string1= string(timer1hh); //string string2= string(timer1mm); //string string3; char out1[5]; sprintf(out1,"%.2d%.2d", timer1hh,timer1mm ); string string3(out1); //string3=string1+string2; serial.println(string3); } void loop() {}
serial output: 0907