Bin schon fast den ganzen Tag dabei und kriege es nicht hin >:(
Ich hab da ein Countdown gebastelt und versuche mit der Menü Lib von Jomelo die Zeit einzustellen.
Mit UP/DOWN setze ich die Zeit, mit ENTER gehts zum nächsten Punkt.
Stunden kann ich UP und DOWN setzen.
Bei Minuten klappt aber nur UP. Drücke ich DOWN, verstellen sich die Minuten und Stunden mit "zufälliger" Zahl.
Kann mal jemand drüber schauen und ein paar hilfreiche Sätze dazu schreiben?!
Der CountDown:
unsigned long previousMillis = 0, Clock, R_clock;
boolean Reset = false, Stop = false;
boolean CountDownTimer()
{
unsigned long currentMillis = millis();
if (!Stop) {
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
Clock--;
if (Clock == 0)
{
Stop = true;
LCDML_BACK_stop(LCDML_BACKEND_heizen);
lcd.setCursor(0, 0);
lcd.print(F("PROGRAMM BEENDET"));
lcd.setCursor(0, 1);
lcd.print(F("HEIZUNG IST AUS"));
lcd.setCursor(0, 3);
lcd.print(F("MAX.TEMP. "));
lcd.print((Temp_top),1);
// LCDML.goRoot();
}
}
}
return !Stop; // return the state of the timer
}
void SetTimer( unsigned long hours, unsigned long minutes, unsigned long seconds)
{
unsigned long _Sec = (seconds / 60), _Min = (minutes / 60);
if(_Sec) minutes += _Sec;
if(_Min) hours += _Min;
Clock = (hours * 3600) + (minutes * 60) + (seconds % 60);
R_clock = Clock;
Stop = false;
}
void SetTimer( uint8_t seconds)
{
Clock = seconds;
R_clock = Clock;
Stop = false;
}
void ResetTimer() { SetTimer(R_clock); Stop = false;}
void StopTimer() { Stop = true;}
uint8_t ShowHours() { return Clock / 3600;}
uint8_t ShowMinutes() { return (Clock / 60) % 60;}
uint8_t ShowSeconds() { return Clock % 60;}
Die Menü Steuerung:
// define global variable
uint8_t g_setDate_cursorPos = 0;
// define help function to set the current time
void HELP_FUNC_set_dat(uint8_t l_i)
{
switch(g_setDate_cursorPos) {
case 0: SetTimer(ShowHours()+l_i, ShowMinutes(), ShowSeconds()); break; // hour
case 1: SetTimer(ShowHours(), ShowMinutes()+l_i, ShowSeconds()); break; // hour
}
}
// define help function to display the current clock settings
void digitalClockDisplay()
{
// init display
lcd.clear();
lcd.setCursor(3,0);
// display hour value
printDigits(ShowHours()); lcd.print(F(":"));
// display minute value, move output when this value is edit
if(g_setDate_cursorPos == 1) { lcd.print(F(" ")); }
printDigits(ShowMinutes()); lcd.print(F(":"));
// display second value
printDigits(ShowSeconds());
// set cursor blink on the correct possion
switch(g_setDate_cursorPos) {
case 0: lcd.setCursor(2,0); lcd.print(F("S")); lcd.setCursor(2,0); lcd.blink(); break; //hour
case 1: lcd.setCursor(6,0); lcd.print(F("M")); lcd.setCursor(6,0); lcd.blink(); break; //min
default: lcd.noBlink(); break;
}
}
// define help function to display digits in front of the value
void printDigits(uint8_t digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
if(digits < 10) lcd.print(F("0")); lcd.print(digits);
}
// *********************************************************************
void LCDML_DISP_setup(LCDML_FUNC_set_date) {digitalClockDisplay(); }
// *********************************************************************
void LCDML_DISP_loop(LCDML_FUNC_set_date)
{
if(LCDML_BUTTON_checkAny()) { // check if any button is presed (enter, up, down, left, right)
if (LCDML_BUTTON_checkUp()) { HELP_FUNC_set_dat(+1); LCDML_BUTTON_resetUp(); }
if (LCDML_BUTTON_checkDown()) { HELP_FUNC_set_dat(-1); LCDML_BUTTON_resetDown(); }
if (LCDML_BUTTON_checkEnter()) { g_setDate_cursorPos=(g_setDate_cursorPos+1)%2; LCDML_BUTTON_resetEnter(); }
digitalClockDisplay();
}
}
void LCDML_DISP_loop_end(LCDML_FUNC_set_date) { lcd.noBlink(); }