Hey Guys,
I'm attempting to take bytes that contain time and date and make them into a string for the purpose of naming a file on an openlog. My clock produces: month, dayOfMonth, hour, and minute in bytes. I tried char() but had no joy. Lots of ascii spaces.
Suppose it was October 28th at 14:12. I would want my file name to be "10281412." Problem is, I have no idea how to make:
byte minute 12;
turn into:
char minute[2] = "12";
I've seen in some examples people using springf(). I liked the one instance where I saw it, but I can't figure out how it works exactly.
Any guidance much appreciated!
- Hunter
I included some (marginal) code below to help you understand what I'm trying to do.
#include "string.h"
// bytes each of the components
byte minute;
byte hour;
byte dayOfMonth;
byte month;
// strings for each of the four components
char Cmonth[2];
char CdayOfmonth[2];
char Chour[2];
char Cminute[2];
char TimeDate[8]; // will contain all of the four components in a string
void setup()
{
Serial.begin(9600);
}
void loop()
{
// Data as it arrives off the clock
minute = 12;
hour = 14;
dayOfMonth = 28;
month = 10;
//**** need something here that will turn bytes into integers
// I have no idea if this is legal, or how I'd go about putting all of my CHAR's into one long string.
TimeDate[8] = {month, dayOfMonth, hour, minute};
Serial.print(TimeDate);
//**** I want to see: "10281412"; That's month dayOfMonth hour minute.
}
Moderator edit:
[code] [/code] tags added.