Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h> // vloženie knižnice pre ovládanie LCD cez I2C
  3. #include <Streaming.h> //http://arduiniana.org/libraries/streaming/
  4. #include <Time.h> //http://playground.arduino.cc/Code/Time
  5. #include <DS1302.h>
  6.  
  7.  
  8. LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
  9.  
  10. // rtc RST, DAT,CLK
  11. DS1302 rtc(2, 3, 4);
  12.  
  13. int h=12; //hodin
  14. int m=20; //minuta
  15. int s=15; //sekunda
  16. int dd; //den
  17. int mm; //mesiac
  18. int yy; //rok
  19. int reading1;
  20. int reading2;
  21. bool btn1=false;
  22. bool btn2=false;
  23. bool changed;
  24. int index=0;
  25. Time t;
  26. void setup() {
  27. pinMode(7, INPUT);
  28. pinMode(6, INPUT);
  29. lcd.init(); // initialize the lcd
  30. rtc.halt(false);
  31. rtc.writeProtect(false);
  32. delay ( 1000 );
  33. Serial.begin(9600);
  34. lcd.backlight();
  35. ////////////////////////////
  36. rtc.setTime(12, 30, 30); //toto vymaz
  37. rtc.setDate(21, 4, 2017); //toto vymaz
  38. /////
  39. }
  40. void loop() {
  41. t = rtc.getTime();
  42. dd=t.date;
  43. mm=prevodMesiacNaCislo(rtc.getMonthStr());
  44. yy=t.year;
  45. h=t.hour;
  46. m=t.min;
  47. s=t.sec;
  48. reading1 =digitalRead(7);
  49. reading2 =digitalRead(6);
  50. if(reading1==1 && btn1)
  51. {
  52. index++;
  53. if(index>5)
  54. index=0;
  55. btn1=false;
  56. }
  57. else if(reading1==0 && !btn1)
  58. btn1=true;
  59. if(reading2==1 && btn2)
  60. {
  61. btn2=false;
  62. if(index==0)
  63. {
  64. h++;
  65. if(h>23)
  66. h=0;
  67. }
  68. else if(index==1)
  69. {
  70. m++;
  71. if(m>59)
  72. m=0;
  73. }
  74. else if(index==2)
  75. {
  76. s++;
  77. if(s>59)
  78. s=0;
  79. }
  80. else if(index==3)
  81. {
  82. dd++;
  83. if(dd>31)
  84. dd=1;
  85. }
  86. else if(index==4)
  87. {
  88. mm++;
  89. if(mm>12)
  90. mm=1;
  91. }
  92. else if(index==5)
  93. {
  94. yy++;
  95. }
  96. ulozCas();
  97. }
  98. else if(reading2==0 && !btn2)
  99. btn2=true;
  100.  
  101.  
  102. lcd.setCursor(0,0);
  103. lcd.print(h);
  104. lcd.print(":");
  105. lcd.print(m);
  106. lcd.print(":");
  107. lcd.print(s);
  108. lcd.setCursor(0,1); //nastav na durhy riadok
  109. lcd.print(dd);
  110. lcd.print("-");
  111. lcd.print(mm);
  112. lcd.print("-");
  113. lcd.print(yy);
  114. /*Serial.println("------");
  115. Serial.print(h);
  116. Serial.print(":");
  117. Serial.print(m);
  118. Serial.print(":");
  119. Serial.print(s);
  120. Serial.print("---");
  121. Serial.print(dd);
  122. Serial.print("-");
  123. Serial.print(mm);
  124. Serial.print("-");
  125. Serial.print(yy);
  126. Serial.print("-");
  127. Serial.println();*/
  128. delay(300);
  129. }
  130.  
  131. void ulozCas(){
  132.  
  133. rtc.setTime(h, m, s); // nastav cas do rtc modulu
  134. rtc.setDate(dd, mm, yy); //nastav datum do rtc modulu
  135. }
  136. int prevodMesiacNaCislo(String mesiac)
  137. {
  138. if(mesiac == "January")
  139. return 1;
  140. else if(mesiac == "February")
  141. return 2;
  142. else if(mesiac == "March")
  143. return 3;
  144. else if(mesiac == "April")
  145. return 4;
  146. else if(mesiac == "May")
  147. return 5;
  148. else if(mesiac == "June")
  149. return 6;
  150. else if(mesiac == "July")
  151. return 7;
  152. else if(mesiac == "August")
  153. return 8;
  154. else if(mesiac == "September")
  155. return 9;
  156. else if(mesiac == "October")
  157. return 10;
  158. else if(mesiac == "November")
  159. return 11;
  160. else if(mesiac == "December")
  161. return 12;
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement