Nastavenie času tlačidlami
Nastavenie času tlačidlami
Zdravím, mám RTC modul DS3231 a potreboval by som nastavovať čas tlačidlami. Pozeral som už nejaké programy no veľmi som tomu nepochopil tak ak by tu bol niekto ochotný mi stým trochu pomôcť a vysvetliť mi to tu, bol by som mu veľmi vďačný. Pozeral som na program od Petana ktory nájdete tu: https://github.com/mylms/Arduino-Matrix ... xClock.ino
Vďaka za každú radu.
Vďaka za každú radu.
Re: Nastavenie času tlačidlami
Z tohoto projektu čerpám - okopíroval jsem právě to MENU. Je neuvěřitelně jednoduché a funkční.
Upravil jsem si to ale na 4 tlačítka (zpět,méně,více,další položka menu).
Mám tam také navíc proměnou "zmena" - hodnoty ukládám jen když se provedla změna,
to mám hlavně kvůli EEPROM aby netrpěla u prototipu při tetování ....
výřez z kodu (je to řízení světel nad akváriem) - jen to menu
vlastní text menu dělám takto (je to pro displej OLED):
protože to dělám pro 4 různé displeje, tak stačí jen změnit tento podprogram
Upravil jsem si to ale na 4 tlačítka (zpět,méně,více,další položka menu).
Mám tam také navíc proměnou "zmena" - hodnoty ukládám jen když se provedla změna,
to mám hlavně kvůli EEPROM aby netrpěla u prototipu při tetování ....
výřez z kodu (je to řízení světel nad akváriem) - jen to menu
Kód: Vybrat vše
//store input to var
presentInput1 = digitalRead(BTN1);
presentInput2 = digitalRead(BTN2);
presentInput3 = digitalRead(BTN3);
presentInput4 = digitalRead(BTN4);
if(systemState < 1) MenuX(0);
// ********************************* MENU ***************************************
switch (systemState) {
case 0:
if (presentInput1 != lastInput1 ) {
//change detected BTN1
if (presentInput1) {
u8g.sleepOff();
MenuX(0);
DisplejSleep=15;
}
}
if (!presentInput4) {
systemState = 1;
DisplejSleep=15;
u8g.sleepOff();
MenuX(0);
//go to "pre"menu
}
break;
case 1:
if (presentInput4 != lastInput4 ) {
//change detected BTN4
if (presentInput4) {
//rising edge detected
//go to MENU1
MenuX(1);
systemState = 2;
}
}
break;
case 2:
//menu 1
//set JAS
if (presentInput1 != lastInput1) {
//change detected BTN1
if (presentInput1) {
//rising edge detected
//EXIT MENU
systemState=0;
MenuX(0);
}
}
if (presentInput3 != lastInput3) {
//change detected BTN3
if (presentInput3) {
//rising edge detected
//pridej JAS
JASpozadovany = JASpozadovany + 5;
if (JASpozadovany >= jasMAX) {JASpozadovany = jasMAX;}
MenuX(1);
zmena = 1;
}
}
if (presentInput2 != lastInput2) {
//change detected BTN2
if (presentInput2) {
//rising edge detected
//uber JAS
JASpozadovany = JASpozadovany - 5;
if (JASpozadovany <= 10) {JASpozadovany = 10;}
MenuX(1);
zmena = 1;
}
}
if (presentInput4 != lastInput4 ) {
//change detected BTN4
if (presentInput4) {
//rising edge detected
//go to MENU2 and SAVE JASpozadovany do EEPROM
if (zmena == 1) EEPROM.write(1, JASpozadovany);
zmena = 0;
hodinSET = hodin;
MenuX(2);
systemState = 3;
}
}
break;
case 3:
//menu 1
//set HODIN
if (presentInput1 != lastInput1) {
//change detected BTN1
if (presentInput1) {
//rising edge detected
//EXIT MENU
systemState=0;
MenuX(0);
}
}
if (presentInput3 != lastInput3) {
//change detected BTN3
if (presentInput3) {
//rising edge detected
//Nastav cas - hodinu +1
DisplejSleep=15;
hodinSET = hodinSET + 1;
if (hodinSET > 23) hodinSET = 0;
MenuX(2);
zmena = 1;
}
}
if (presentInput2 != lastInput2) {
//change detected BTN2
if (presentInput2) {
//rising edge detected
//Nastav cas - hodinu -1
hodinSET = hodinSET - 1;
if (hodinSET > 250) hodinSET = 23;
MenuX(2);
zmena = 1;
}
}
if (presentInput4 != lastInput4 ) {
//change detected BTN4
if (presentInput4) {
//rising edge detected
//go to MENU3
minutSET = minut;
MenuX(3);
systemState = 4;
}
}
break;
case 4:
//menu 3
//set minuty
if (presentInput1 != lastInput1) {
//change detected BTN1
if (presentInput1) {
//rising edge detected
//EXIT MENU
systemState=0;
MenuX(0);
}
}
if (presentInput3 != lastInput3) {
//change detected BTN3
if (presentInput3) {
//rising edge detected
//Nastav cas - minut +1
minutSET = minutSET + 1;
if (minutSET > 59) minutSET = 0;
MenuX(3);
zmena = 1;
}
}
if (presentInput2 != lastInput2) {
//change detected BTN2
if (presentInput2) {
//rising edge detected
//Nastav cas - hodinu -1
minutSET = minutSET - 1;
if (minutSET > 250) minutSET = 59;
MenuX(3);
zmena = 1;
}
}
if (presentInput4 != lastInput4 ) {
//change detected BTN4
if (presentInput4) {
//rising edge detected
//go to MENU4
systemState = 5;
denSET = den;
MenuX(4);
}
}
break;
case 5:
//menu 4
//set DEN
if (presentInput1 != lastInput1) {
//change detected BTN1
if (presentInput1) {
//rising edge detected
//EXIT MENU
systemState=0;
MenuX(0);
}
}
if (presentInput3 != lastInput3) {
//change detected BTN3
if (presentInput3) {
//rising edge detected
//Nastav DEN - DEN +1
denSET = denSET + 1;
if (denSET > 31) denSET = 1;
MenuX(4);
zmena = 1;
}
}
if (presentInput2 != lastInput2) {
//change detected BTN2
if (presentInput2) {
//rising edge detected
//Nastav DEN - DEN -1
denSET = denSET - 1;
if (denSET > 250) denSET = 31;
MenuX(4);
zmena = 1;
}
}
if (presentInput4 != lastInput4 ) {
//change detected BTN4
if (presentInput4) {
//rising edge detected
//go to MENU5
systemState = 6;
mesicSET = mesic;
MenuX(5);
}
}
break;
case 6:
//menu 5
//set MESIC
if (presentInput1 != lastInput1) {
//change detected BTN1
if (presentInput1) {
//rising edge detected
//EXIT MENU
systemState=0;
MenuX(0);
}
}
if (presentInput3 != lastInput3) {
//change detected BTN3
if (presentInput3) {
//rising edge detected
//Nastav MESIC - MESICN +1
mesicSET = mesicSET + 1;
if (mesicSET > 12) mesicSET = 1;
MenuX(5);
zmena = 1;
}
}
if (presentInput2 != lastInput2) {
//change detected BTN2
if (presentInput2) {
//rising edge detected
//Nastav MESIC - MESIC -1
mesicSET = mesicSET - 1;
if (mesicSET > 250) mesicSET = 12;
MenuX(5);
zmena = 1;
}
}
if (presentInput4 != lastInput4 ) {
//change detected BTN4
if (presentInput4) {
//rising edge detected
//go to MENU4
systemState = 7;
rokSET = rok;
MenuX(6);
}
}
break;
case 7:
//menu 5
//set ROK
if (presentInput1 != lastInput1) {
//change detected BTN1
if (presentInput1) {
//rising edge detected
//EXIT MENU
systemState=0;
MenuX(0);
}
}
if (presentInput3 != lastInput3) {
//change detected BTN3
if (presentInput3) {
//rising edge detected
//Nastav ROK - ROKN +1
rokSET = rokSET + 1;
if (rokSET > 2030) rokSET = 2018;
MenuX(6);
zmena = 1;
}
}
if (presentInput2 != lastInput2) {
//change detected BTN2
if (presentInput2) {
//rising edge detected
//Nastav ROK - ROK -1
rokSET = rokSET - 1;
if (rokSET < 2018) rokSET = 2030;
MenuX(6);
zmena = 1;
}
}
if (presentInput4 != lastInput4 ) {
//change detected BTN4
if (presentInput4) {
//rising edge detected
//go to MENU4
if(zmena == 1) DS1307.adjust(DateTime(rokSET, mesicSET, denSET, hodinSET, minutSET, 00));
DateTime datumCas = DS1307.now(); //zobrazení času
hodin = datumCas.hour(); // vycti aktualni hodinu
minut = datumCas.minute(); // vycti aktualni minutu
rok = datumCas.year();
mesic = datumCas.month();
den = datumCas.day();
MenuX(0);
systemState = 0;
zmena = 0;
protože to dělám pro 4 různé displeje, tak stačí jen změnit tento podprogram
Kód: Vybrat vše
// ************************ PODPROGRAMY
void MenuX(byte cislomenu)
{
switch (cislomenu) {
case 0:
// picture loop
u8g.firstPage();
do {
u8g.setFont(u8g_font_fur14r);
u8g.drawStr( 0, 14, "AKVA v1.24");
u8g.setFont(u8g_font_fur25n);
DateTime datumCas = DS1307.now(); //zobrazení času
sprintf(cas, "%02d:%02d", datumCas.hour(), datumCas.minute());
u8g.drawStr( 18, 55, cas);
} while( u8g.nextPage() ); // graphic commands to redraw the complete screen should be placed here
break;
case 1:
// picture loop
DisplejSleep=15;
u8g.firstPage();
do {
itoa(JASpozadovany, tmp_string, 10);
u8g.setFont(u8g_font_fur14r);
u8g.drawStr( 0, 14, "Nastav JAS");
u8g.setFont(u8g_font_fur25n);
u8g.drawStr( 18, 55, tmp_string);
} while( u8g.nextPage() ); // graphic commands to redraw the complete screen should be placed here
break;
case 2:
// picture loop
DisplejSleep=15;
u8g.firstPage();
do {
itoa(hodinSET, tmp_string, 10);
u8g.setFont(u8g_font_fur14r);
u8g.drawStr( 0, 14, "Nastav HOD");
u8g.setFont(u8g_font_fur25n);
u8g.drawStr( 18, 55, tmp_string);
} while( u8g.nextPage() ); // graphic commands to redraw the complete screen should be placed here
break;
case 3:
// picture loop
DisplejSleep=15;
u8g.firstPage();
do {
itoa(minutSET, tmp_string, 10);
u8g.setFont(u8g_font_fur14r);
u8g.drawStr( 0, 14, "Nastav MIN");
u8g.setFont(u8g_font_fur25n);
u8g.drawStr( 18, 55, tmp_string);
} while( u8g.nextPage() ); // graphic commands to redraw the complete screen should be placed here
break;
case 4:
// picture loop
DisplejSleep=15;
u8g.firstPage();
do {
itoa(denSET, tmp_string, 10);
u8g.setFont(u8g_font_fur14r);
u8g.drawStr( 0, 14, "Nastav DEN");
u8g.setFont(u8g_font_fur25n);
u8g.drawStr( 18, 55, tmp_string);
} while( u8g.nextPage() ); // graphic commands to redraw the complete screen should be placed here
break;
case 5:
// picture loop
DisplejSleep=15;
u8g.firstPage();
do {
itoa(mesicSET, tmp_string, 10);
u8g.setFont(u8g_font_fur14r);
u8g.drawStr( 0, 14, "Nastav MESIC");
u8g.setFont(u8g_font_fur25n);
u8g.drawStr( 18, 55, tmp_string);
} while( u8g.nextPage() ); // graphic commands to redraw the complete screen should be placed here
break;
case 6:
// picture loop
DisplejSleep=15;
u8g.firstPage();
do {
itoa(rokSET, tmp_string, 10);
u8g.setFont(u8g_font_fur14r);
u8g.drawStr( 0, 14, "Nastav ROK");
u8g.setFont(u8g_font_fur25n);
u8g.drawStr( 18, 55, tmp_string);
} while( u8g.nextPage() ); // graphic commands to redraw the complete screen should be placed here
break;
}
}
UNO, NANO, Mikro, PRO mini, DUE, ESP32S2, RPi PICO
Pavel1TU
"Správně napsaný kod lze číst jako knihu"
Pavel1TU
"Správně napsaný kod lze číst jako knihu"
Re: Nastavenie času tlačidlami
Funkci EEPROM.update() znáš?Mám tam také navíc proměnou "zmena" - hodnoty ukládám jen když se provedla změna,
to mám hlavně kvůli EEPROM aby netrpěla u prototipu při tetování ....
Re: Nastavenie času tlačidlami
lol - evidentně neee, díky
UNO, NANO, Mikro, PRO mini, DUE, ESP32S2, RPi PICO
Pavel1TU
"Správně napsaný kod lze číst jako knihu"
Pavel1TU
"Správně napsaný kod lze číst jako knihu"
Re: Nastavenie času tlačidlami
Vďaka za radu skúsim to prispôsobiť ku svojmu programu
Kdo je online
Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 1 host