Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h> // vloženie knižnice pre ovládanie LCD cez I2C
- #include <Streaming.h> //http://arduiniana.org/libraries/streaming/
- #include <Time.h> //http://playground.arduino.cc/Code/Time
- #include <DS1302.h>
- LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
- // rtc RST, DAT,CLK
- DS1302 rtc(2, 3, 4);
- int h=12; //hodin
- int m=20; //minuta
- int s=15; //sekunda
- int dd; //den
- int mm; //mesiac
- int yy; //rok
- int reading1;
- int reading2;
- bool btn1=false;
- bool btn2=false;
- bool changed;
- int index=0;
- Time t;
- void setup() {
- pinMode(7, INPUT);
- pinMode(6, INPUT);
- lcd.init(); // initialize the lcd
- rtc.halt(false);
- rtc.writeProtect(false);
- delay ( 1000 );
- Serial.begin(9600);
- lcd.backlight();
- ////////////////////////////
- rtc.setTime(12, 30, 30); //toto vymaz
- rtc.setDate(21, 4, 2017); //toto vymaz
- /////
- }
- void loop() {
- t = rtc.getTime();
- dd=t.date;
- mm=prevodMesiacNaCislo(rtc.getMonthStr());
- yy=t.year;
- h=t.hour;
- m=t.min;
- s=t.sec;
- reading1 =digitalRead(7);
- reading2 =digitalRead(6);
- if(reading1==1 && btn1)
- {
- index++;
- if(index>5)
- index=0;
- btn1=false;
- }
- else if(reading1==0 && !btn1)
- btn1=true;
- if(reading2==1 && btn2)
- {
- btn2=false;
- if(index==0)
- {
- h++;
- if(h>23)
- h=0;
- }
- else if(index==1)
- {
- m++;
- if(m>59)
- m=0;
- }
- else if(index==2)
- {
- s++;
- if(s>59)
- s=0;
- }
- else if(index==3)
- {
- dd++;
- if(dd>31)
- dd=1;
- }
- else if(index==4)
- {
- mm++;
- if(mm>12)
- mm=1;
- }
- else if(index==5)
- {
- yy++;
- }
- ulozCas();
- }
- else if(reading2==0 && !btn2)
- btn2=true;
- lcd.setCursor(0,0);
- lcd.print(h);
- lcd.print(":");
- lcd.print(m);
- lcd.print(":");
- lcd.print(s);
- lcd.setCursor(0,1); //nastav na durhy riadok
- lcd.print(dd);
- lcd.print("-");
- lcd.print(mm);
- lcd.print("-");
- lcd.print(yy);
- /*Serial.println("------");
- Serial.print(h);
- Serial.print(":");
- Serial.print(m);
- Serial.print(":");
- Serial.print(s);
- Serial.print("---");
- Serial.print(dd);
- Serial.print("-");
- Serial.print(mm);
- Serial.print("-");
- Serial.print(yy);
- Serial.print("-");
- Serial.println();*/
- delay(300);
- }
- void ulozCas(){
- rtc.setTime(h, m, s); // nastav cas do rtc modulu
- rtc.setDate(dd, mm, yy); //nastav datum do rtc modulu
- }
- int prevodMesiacNaCislo(String mesiac)
- {
- if(mesiac == "January")
- return 1;
- else if(mesiac == "February")
- return 2;
- else if(mesiac == "March")
- return 3;
- else if(mesiac == "April")
- return 4;
- else if(mesiac == "May")
- return 5;
- else if(mesiac == "June")
- return 6;
- else if(mesiac == "July")
- return 7;
- else if(mesiac == "August")
- return 8;
- else if(mesiac == "September")
- return 9;
- else if(mesiac == "October")
- return 10;
- else if(mesiac == "November")
- return 11;
- else if(mesiac == "December")
- return 12;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement