Search code examples
arduino

Arduino multiple variables in string


I am trying to get a string containing the uptime of my Arduino. I'm using this code:

long t = millis() / 1000;
word h = t / 3600;
byte m = (t / 60) % 60;
byte s = t % 60;
String uptime =  h/10 + h%10 + m/10 + m%10 + s/10 + s%10;

But I get 'invalid conversion' errors. Should I do this with sprintf or something?


Solution

  • If you are forced to use C: yes, sprintf or, much better, snprintf is the right way to go for you. If you are using C++ and the STL is available, you should use std::string (but I am not sure if this is there).