Hi,
I'm trying to get the minutes from an RTC using RTCLib to use with a 7 segment display. Everything else is already working, I just need the minutes I've got the 10 spot working using a long handed version, but need the ones spot.
Thanks Nick. So I've used sprintf, but am unclear how to get the last character.
This is what I have so far. How do I get the last character out ?
int parseMinutes()
{
DateTime now = RTC.now();
char buffer [10];
int n;
int a =now.minute();
n =sprintf (buffer, "%d", a);
Serial.print("Buffer = ");
Serial.print(buffer);
int len = strlen(buffer);
Serial.print(" length = ");
Serial.println(len);
}
An easier method to write all your 7 segments displays at once (assuming you want hours, minutes and seconds):
char time_str[7];
sprintf( time_str, "%02d%02d%02d", now.hour(), now.minute(), now.second() );
for (uint8_t i = 0; i < 6; i++ )
matrix.writeDigitNum( i+1, time_str[i] - '0' ); //not sure if the first 7-seg is id 1 but whatever, modify if needed
Pauly:
Thanks Nick. So I've used sprintf, but am unclear how to get the last character.
This is what I have so far. How do I get the last character out ?
n =sprintf (buffer, "%d", a);
You could instead do this:
sprintf(buffer,"%.2d",a);
...then you'd know that buffer contained two digits (prefixed with 0 if a < 10). buffer[0] is the first digit, and buffer[1] is the second. And, as mentioned, you can do that with the the rest of the time elements as well, even putting them all into the same buffer: