A soros kiíratást próbáltam, nem láttam hibát.
A menürendszer nincs teljesen kész, csak az rész működik (működne) ami az időt állítja be.
Kód: Egész kijelölése
#include <stdio.h>
#include <DS1302.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
namespace {
const int kCePin = 2; // Chip Enable
const int kIoPin = 3; // Input/Output
const int kSclkPin = 4; // Serial Clock
DS1302 rtc(kCePin, kIoPin, kSclkPin);
String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Vasarnap";
case Time::kMonday: return "Hetfo";
case Time::kTuesday: return "Kedd";
case Time::kWednesday: return "Szerda";
case Time::kThursday: return "Csutortok";
case Time::kFriday: return "Pentek";
case Time::kSaturday: return "Szombat";
}
return "(unknown day)";
}
} // namespace
int ev;
int ho;
int nap;
int ora;
int perc;
int mp;
byte quit = 1;
byte menu = 0;
byte submenu = 0;
byte almenu;
//---------------------------------------------------------------------------------------
//*******************************************************************************
void setup() {
lcd.begin();
lcd.backlight();
lcd.clear();
Serial.begin(9600);
//----------------------------------------------
rtc.writeProtect(false);
rtc.halt(false);
//********************************************************************************
// Sunday, September 22, 2013 at 01:38:50.
// Time t(2017, 3, 2, 20, 00, 00, Time::kWednesday); // idő beállítása
// Set the time and date on the chip.
//rtc.time(t); // idő küldése
// Time t(ev, ho, nap, ora, perc, 00, Time::kMonday);
// rtc.time(t);
//******************************************************************************
pinMode (5, OUTPUT); // rtc pinek
pinMode (6,OUTPUT);
digitalWrite (5, HIGH);
digitalWrite (6, LOW);
lcd.setCursor(0,0);
lcd.print("Indul");
delay(1000);
lcd.clear();
}
//---------------------------------------------------------------------------
void loop() {
// Get the current time and date from the chip.
Time t = rtc.time();
// Name the day of the week.
const String day = dayAsString(t.day);
// Format the time and date and insert into the temporary buffer.
char buf[50];
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
day.c_str(),
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);
ev = t.yr;
ho = t.mon;
nap = t.date;
ora = t.hr;
perc = t.min;
mp = t.sec;
if (button() == 1)
{menu ++;
lcd.clear();}
if (button() == 4)
{menu --;
lcd.clear();}
while (menu != 0)
{
//Serial.println(menu) ;
if (button() == 1)
{menu ++;
//lcd.clear();
}
if (button() == 4)
{menu --;
//lcd.clear();
}
if (menu == 0)
{uzem();}
if (menu == 1)
{menualap();}
if ( menu > 0)
{menu = 1;}
if ( menu <= 0 )
{ menu = 0;}
}
// Time t = rtc.time();
/*
const String day = dayAsString(t.day);
char buf[50];
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
day.c_str(),
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);
*/
uzem();
//Serial.println(day);
}
//------------------------------------------------------- alap képernyő
void uzem()
{
submenu = 0, almenu = 0;
Serial.println ("menu");
Serial.println (menu);
Serial.println ("submenu");
Serial.println (submenu);
Serial.println ("almenu");
Serial.println (almenu);
//lcd.clear();
Time t = rtc.time();
const String day = dayAsString(t.day);
/*
char buf[50];
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
day.c_str(),
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);
*/
ev = t.yr;
ho = t.mon;
nap = t.date;
ora = t.hr;
perc = t.min;
mp = t.sec;
lcd.setCursor(5,0);
lcd.print(ev);
lcd.setCursor(9,0);
lcd.print("-");
lcd.setCursor(10,0);
lcdprint2(ho);
lcd.setCursor(12,0);
lcd.print("-");
lcd.setCursor(13,0);
lcdprint2(nap);
lcd.setCursor(0,1);
lcdprint2(ora);
lcd.setCursor(2,1);
lcd.print("-");
lcd.setCursor(3,1);
lcdprint2(perc);
lcd.setCursor(5,1);
lcd.print("-");
lcd.setCursor(6,1);
lcdprint2 (mp);
lcd.setCursor(9,1);
lcd.print(day);
if (menu <=0)
{menu = 0;}
//Serial.println (t.day);
//printTime();
//almenu=0;
//submenu = 0;
}
//------------------------------------------- // ket szamjeggyel irja ki a megadott szamot
void lcdprint2(char cc)
{
lcd.print(cc/10);
lcd.print(cc%10);
return;
}
//------------------------------------------------- gomb kezelés
unsigned char button()
{
unsigned int tempbtn = 0;
unsigned char result = 0;
tempbtn = analogRead(A0);
if(tempbtn < 700)
{delay (75);
if (tempbtn < 700)
{result += 1;}
}
//tempbtn = 0;
tempbtn = analogRead(A1);
if(tempbtn < 700)
{delay (75);
if (tempbtn < 700)
{result += 2;}
}
tempbtn = analogRead(A2);
if(tempbtn < 700)
{delay (75);
if (tempbtn < 700)
{result += 3;}
}
tempbtn = analogRead(A3);
if(tempbtn < 700)
{delay (75);
if (tempbtn < 700)
{result += 4;}
}
return result;
}
//------------------------------------------------------------- Menu
void menualap()
{
Serial.println ("menu");
Serial.println (menu);
Serial.println ("submenu");
Serial.println (submenu);
Serial.println ("almenu");
Serial.println (almenu);
lcd.setCursor(1,0);
lcd.print("Ciklikus etetes");
lcd.setCursor(1,1);
lcd.print("Heti ciklikus e.");
lcd.setCursor(1,2);
lcd.print("Datum szerinti e.");
lcd.setCursor(1,3);
lcd.print("Ido beallitas");
if (button() == 4)
{
lcd.clear();
return menu = 0, submenu = 0, almenu = 0;
uzem();
}
if (button() == 2)
{almenu ++;
lcd.setCursor(0,(almenu-1));
lcd.print(" ");
}
if (button() == 3)
{almenu --;
lcd.setCursor(0,(almenu+1));
lcd.print(" ");
}
lcd.setCursor(0,almenu);
lcd.print("*");
if (button() == 1)
{
if ( almenu == 0)
{lcd.clear();
menu1();
}
if ( almenu == 1)
{lcd.clear();
menu2();
}
if ( almenu == 2)
{lcd.clear();
menu3();
}
if ( almenu == 3)
{
lcd.clear();
menu4();}
}
}
//------------------------------------------------------------------------------------1. almenü
void menu1()
{lcd.setCursor(0,0);
lcd.print("menu2");
delay(1000);}
//--------------------------------------------------------------------------------- 2. almenü
void menu2()
{lcd.setCursor(0,0);
lcd.print("menu3");
delay(1000);}
//---------------------------------------------------------------------------------3. almenü
void menu3()
{lcd.setCursor(0,0);
lcd.print("menu4");
delay(1000);}
//------------------------------------------------------------------------------ 4. almenü idő beállítása
void menu4()
{
const String napok[7] = {"Hetfo", " Kedd", " Szerda", " Csutortok", " Pentek", " Szombat" , " Vasarnap"};
byte tombszam;
lcd.setCursor(1,0);
lcd.print(ev);
lcd.setCursor(7,0);
lcdprint2(ho);
lcd.setCursor(11,0);
lcdprint2(nap);
lcd.setCursor(2,1);
lcdprint2(ora);
lcd.setCursor(6,1);
lcdprint2(perc);
lcd.setCursor(10,1);
lcd.print(napok[0]);
if (button() == 1)
{submenu ++;}
if (button() == 4)
{submenu --;}
//------------------------------- év
while ( quit == 1)
{
if (submenu <= 0)
{submenu = 0;}
if (button() == 1)
{submenu ++;}
if (button() == 4)
{submenu --;
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(4,1);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(" ");
}
//------------------------------- év
if (submenu == 1)
{lcd.setCursor(0,0);
lcd.print("*");
if (button() == 2)
{ev ++;
lcd.setCursor(1,0);
lcd.print(ev);}
if (button() == 3)
{ev --;
if (ev <= 2016)
{ev = 2016;}
lcd.setCursor(1,0);
lcd.print(ev);}
if (ev <= 2016)
{ev = 2016;}
}
//----------------------------- hónap
if (submenu == 2)
{lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(6,0);
lcd.print("*");
if (button() == 2)
{ho ++;
if (ho >= 12)
{ho = 12;}
lcdprint2(ho);
lcd.setCursor(11,0);}
if (button() == 3)
{ho --;
if (ho <= 1)
{ho = 1;}
lcdprint2(ho);
lcd.setCursor(11,0);}
}
//---------------------------------- nap
if (submenu == 3)
{lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(10,0);
lcd.print("*");
if (button() == 2)
{nap ++;
if (nap >= 31)
{nap = 31;}
lcd.setCursor(11,0);
lcdprint2(nap);}
if (button() == 3)
{nap --;
if (nap <= 1)
{nap = 1;}
lcd.setCursor(11,0);
lcdprint2(nap);}
}
//---------------------------------- óra
if (submenu == 4)
{lcd.setCursor(10,0);
lcd.print(" ");
lcd.setCursor(1,1);
lcd.print("*");
if (button() == 2)
{ora ++;
if (ora >= 23)
{ora = 23;}
lcd.setCursor(2,1);
lcdprint2(ora);}
if (button() == 3)
{ora --;
if (ora <= 0)
{ora = 0;}
lcd.setCursor(2,1);
lcdprint2(ora);}
}
//---------------------------------- perc
if (submenu == 5)
{lcd.setCursor(1,1);
lcd.print(" ");
lcd.setCursor(5,1);
lcd.print("*");
if (button() == 2)
{perc ++;
if (perc >= 59)
{perc = 59;}
lcd.setCursor(6,1);
lcdprint2(perc);}
if (button() == 3)
{perc --;
if (perc <= 1)
{ora = 1;}
lcd.setCursor(6,1);
lcdprint2(perc);}
}
//---------------------------------- hét napja
if (submenu == 6)
{lcd.setCursor(5,1);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print("*");
if (button() == 2)
{tombszam ++;
if (tombszam >= 6)
{tombszam = 6;}
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(napok[tombszam]);}
if (button() == 3)
{tombszam --;
if (tombszam <= 0)
{tombszam = 0;}
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(napok[tombszam]);
}
Serial.println (tombszam);
}
//-------------------------------------
if (submenu == 7)
{
menu = 0;
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Datum mentese !! ");
delay(1000);
lcd.clear();
if (tombszam == 0)
{Time t(ev, ho, nap, ora, perc, 0, Time::kMonday);
rtc.time(t); }
if (tombszam == 1)
{Time t(ev, ho, nap, ora, perc, 0, Time::kTuesday);
rtc.time(t);}
if (tombszam == 2)
{Time t(ev, ho, nap, ora, perc, 00, Time::kWednesday);
rtc.time(t);}
if (tombszam == 3)
{Time t(ev, ho, nap, ora, perc, 00, Time::kThursday);
rtc.time(t);}
if (tombszam == 4);
{Time t(ev, ho, nap, ora, perc, 00, Time::kFriday);
rtc.time(t);}
if (tombszam == 5)
{Time t(ev, ho, nap, ora, perc, 00, Time::kSaturday);
rtc.time(t);}
if (tombszam == 6)
{Time t(ev, ho, nap, ora, perc, 00, Time::kSunday);
rtc.time(t);}
quit = 0;
// Sunday, September 22, 2013 at 01:38:50. idő beállítás tesztelésrte
// Time t(2013, 9, 22, 1, 38, 50, Time::kSunday);
// Time t(ev, ho, nap, ora, perc, 00, Time::kSaturday);
// Set the time and date on the chip.
//rtc.time(t);
}
}
menu = 0;
submenu = 0;
}
//-*------------------------------------ Teljes dátum kiírása soros portra
void printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();
// Name the day of the week.
const String day = dayAsString(t.day);
// Format the time and date and insert into the temporary buffer.
char buf[50];
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
day.c_str(),
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);
// Print the formatted string to serial so we can see the time.
Serial.println(buf);
}
Remélem nem túl sok balgaságot írtam.
Blokkdiagramot nem csináltam. (még, de ha kell a segítséghez csinálok.)