I am taking a time without the time-functions on an LCD display. The seconds and minutes etc., must continue.
This is the current code:
- include "mbed.h"
- include "TextLCD.h"
TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);
int hours = 23;
int minutes = 58;
int seconds = 59;
int day = 1;
int month = 1;
int year = 1;
Ticker rhythm;
void myrhythm()
{
seconds++;
if(seconds>59) {
minutes++;
seconds=0;
}
if(minutes>59) {
hours++;
minutes=0;
}
if(hours>23) {
hours=0;
day++;
}
if(day>31) {
month++;
day=1;
}
if(month>12) {
year++;
month=1;
}
}
int main()
{
while (1) {
lcd.locate(0,0);
lcd.printf("%02d:%02d:%02d", hours, minutes, seconds);
lcd.locate(0,1);
lcd.printf("%02d/%02d/%02d", day, month, year);
rhythm.attach (&myrhythm, 1.0);
}
}
Please help me, I don't know what I must do. ;)
I am taking a time without the time-functions on an LCD display. The seconds and minutes etc., must continue.
This is the current code:
TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);
int hours = 23; int minutes = 58; int seconds = 59;
int day = 1; int month = 1; int year = 1;
Ticker rhythm;
void myrhythm() { seconds++; if(seconds>59) { minutes++; seconds=0; }
if(minutes>59) { hours++; minutes=0; }
if(hours>23) { hours=0; day++; }
if(day>31) { month++; day=1; }
if(month>12) { year++; month=1; } }
int main() { while (1) { lcd.locate(0,0); lcd.printf("%02d:%02d:%02d", hours, minutes, seconds); lcd.locate(0,1); lcd.printf("%02d/%02d/%02d", day, month, year);
rhythm.attach (&myrhythm, 1.0); } }
Please help me, I don't know what I must do. ;)