Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <Servo.h>
  3.  
  4. LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
  5.  
  6. int starttime;
  7. int activetime;
  8. int prevoustime = 0;
  9.  
  10. int servoPin = 12;
  11. Servo servo;
  12. int angle = 0;
  13. int kuittaus = 0;
  14.  
  15. int hours = 0;
  16. int mins = 0;
  17.  
  18. int ahours = 0;
  19. int amins = 0;
  20.  
  21. void setup()
  22. {
  23. lcd.begin(16, 2);
  24. lcd.clear();
  25.  
  26. servo.attach(servoPin);
  27.  
  28. Serial.begin(9600);
  29.  
  30. pinMode(13, INPUT);
  31. digitalWrite(13, HIGH);
  32. pinMode(11, INPUT);
  33. digitalWrite(11, HIGH);
  34. pinMode(10, INPUT);
  35. digitalWrite(10, HIGH);
  36.  
  37. pinMode(8, INPUT);
  38. digitalWrite(8, HIGH);
  39. pinMode(A0, OUTPUT);
  40. digitalWrite(A0, HIGH);
  41.  
  42. pinMode(9, OUTPUT);
  43.  
  44. starttime = millis()/1000;
  45. }
  46.  
  47. void loop()
  48. {
  49. while(digitalRead(8) == LOW)
  50. {
  51. lcd.setCursor(6,1);
  52. lcd.print("Alarm");
  53. lcd.setCursor(6,0);
  54. if(digitalRead(11) == LOW)
  55. {
  56. amins++;
  57. }
  58. else if (digitalRead(10) == LOW)
  59. {
  60. ahours++;
  61. }
  62. lcd.setCursor(6,0);
  63.  
  64. if(ahours < 10)
  65. {
  66. lcd.print("0");
  67. lcd.print(ahours);
  68. }
  69. else
  70. {
  71. lcd.print(ahours);
  72. }
  73.  
  74. lcd.print(":");
  75.  
  76. if (amins < 10)
  77. {
  78. lcd.print("0");
  79. lcd.print(amins);
  80. }
  81. else
  82. {
  83. lcd.print(amins);
  84. }
  85. if(amins > 59)
  86. {
  87. ahours++;
  88. amins = 0;
  89. }
  90. if(ahours > 23)
  91. {
  92. ahours = 0;
  93. }
  94. delay(500);
  95. lcd.clear();
  96. }
  97.  
  98. if(digitalRead(13) == LOW)
  99. {
  100.  
  101. lcd.setCursor(5,1);
  102. lcd.print("Set Time");
  103. lcd.setCursor(6,0);
  104. if(digitalRead(11) == LOW)
  105. {
  106. mins++;
  107. }
  108. else if (digitalRead(10) == LOW)
  109. {
  110. hours++;
  111. }
  112.  
  113.  
  114. }
  115.  
  116. activetime = (millis() / 1000) - starttime;
  117. if(prevoustime < (activetime - 59))
  118. {
  119. mins++;
  120. prevoustime = activetime;
  121. }
  122.  
  123. if(mins > 59)
  124. {
  125. hours++;
  126. mins = 0;
  127. }
  128.  
  129. if(hours > 23)
  130. {
  131. hours = 0;
  132. }
  133.  
  134.  
  135. lcd.setCursor(6,0);
  136.  
  137. if(hours < 10)
  138. {
  139. lcd.print("0");
  140. lcd.print(hours);
  141. }
  142. else
  143. {
  144. lcd.print(hours);
  145. }
  146.  
  147. lcd.print(":");
  148.  
  149. if (mins < 10)
  150. {
  151. lcd.print("0");
  152. lcd.print(mins);
  153. }
  154. else
  155. {
  156. lcd.print(mins);
  157. }
  158.  
  159.  
  160.  
  161. if(ahours == hours && amins == mins && amins != 0 && kuittaus == 0)
  162. {
  163. tone(9, 1000, 200);
  164. delay(200);
  165. noTone(9);
  166. delay(200);
  167. servo.write(180);
  168. }
  169. else if(kuittaus == 1{
  170. servo.write(0);
  171. noTone(9);
  172. }
  173. else
  174. {
  175. delay(300);
  176. }
  177. lcd.clear();
  178.  
  179.  
  180. Serial.println(mins);
  181. Serial.println(hours);
  182. Serial.println("");
  183. Serial.println(amins);
  184. Serial.println(ahours);
  185. Serial.println("");
  186. Serial.println(activetime);
  187. Serial.println(prevoustime);
  188. Serial.println(starttime);
  189. Serial.println("");
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement