Hi
I have written some code that takes the amount on minutes called durationInMins.
durationInMins is converted to 2 byte variables named hours, and mins.
I don't know how to convert the byte variables hours, mins to a char array.
I'm trying to fill the character array with the data as follows "hh:mm" format.
Here is what I have so far I have it running on my Uno board.
Thank you
Don
#include <math.h>
void setup()
{
Serial.begin(115200);
}
void loop()
{
char duration[] = {" : "};
int durationInMins = 490;
byte hours = 0;
byte mins = 0;
double i, r;
r = durationInMins * .01666;
Serial.print("Durationin mins: ");
Serial.println(durationInMins);
r = modf(r, &i);
r = r * 60;
mins = byte(round(r));
hours = byte(i);
Serial.print("Hours: ");
Serial.println(hours);
Serial.print("Mins: ");
Serial.println(mins);
Serial.println();
/*
I now want to convert
variable hours to a character array;
and variable mins to a character array
then put them in char array duration
char duaration[] = {"hh:mm"};
*/
Serial.println(duration);
Serial.println();
for(;;){}
}
Peter and Mark
Thanks I have a hard time coming up with simple solutions to my problems... I hope this gets better with time. Mark I understand that code in setup runs once but is there a reason why putting that for loop in Loop() is a bad idea? I want to learn do's and don't of Arduino. I've use the for loop in WinAvr.
Can you recommend books, or web sites to help learn the best approach solving the task needed?
I knew of modus arithmetic but wasn't sure how to use it.
Don
is there a reason why putting that for loop in Loop() is a bad idea?
Not exactly, but your example is rather artificial - most arduino sketches will run through loop more than once - they're often used as controllers for some external system. In a learning exercise such as yours it really doesn't matter, but generally, if something will run only once at the beginning, particularly if other people are going to see the code, it should live in setup.
Wildbill
I appreciate your feedback, I will follow the convention as I move forward.
Thank you everyone who responded to the topic
I always learn something new with every topic I post in the forum. You all are respected!
Don