Advertisement
Guest User

Water Splash Alarm Clock

a guest
Apr 18th, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include<Keypad.h>
  3. #include<Time.h>
  4.  
  5.  
  6. LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //set up pins to lcd
  7. const byte ROWS = 4; //four rows on keypad
  8. const byte COLS = 4; //three columns on keypad
  9. char keys[ROWS][COLS] = {
  10. {'1','2','3','A'},
  11. {'4','5','6','B'},
  12. {'7','8','9','C'},
  13. {'*','0','#','D'}
  14. };
  15. byte rowPins[ROWS] = {30, 32, 34, 36}; //connect to the row pinouts of the keypad
  16. byte colPins[COLS] = {26, 24, 22, 38}; //connect to the column pinouts of the keypad
  17. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  18. int place = 0;
  19. int hours = 99;//set hours to 99 so we know if it has been altered
  20. int minutes = 99;//set minutes to 99 so we know if it has been altered
  21. boolean keeplooping = true;
  22. int alarmhour = 99;//set to 99 so we know if it has been altered
  23. int alarmminute = 99;//set to 99 se we know if it has been altered
  24. int currenthour;
  25. int currentminute;
  26.  
  27.  
  28.  
  29.  
  30. void setup(){
  31. pinMode(5, OUTPUT); //initialize pins attached to base of transistors supplying current to motor
  32. pinMode(4, OUTPUT);
  33. pinMode(7, OUTPUT);
  34. pinMode(6, OUTPUT);
  35. lcd.begin(16,2);// set up the LCD's number of columns and rows
  36. lcd.print("Current Time");//prompt user for current timne
  37. lcd.setCursor(0, 1);//set to print on row 1(second row)
  38. lcd.print("hours # minutes");//tell user the input format
  39. delay(5000);
  40. spin(4000);//dump water
  41. enter_time(); //have user enter current time
  42. setTime(hours, minutes, 30, 13, 4, 2015);//set time to user defined time, using the date I created this program as the days months and years
  43. lcd.clear();
  44. lcd.print("Enter alarm time");
  45. enter_alarm_hour(); //have user set alarm time
  46. enter_alarm_minute();
  47. }
  48. void loop (){
  49. delay(10000);//check time every ten seconds
  50. currenthour = hour();//get hour
  51. currentminute = minute();//get minute
  52. lcd.clear();//clear screen
  53. lcd.print(currenthour);//print hour:minute
  54. lcd.print(":");
  55. if(currentminute<10){lcd.print(0);}//make it say 11:01 instead of 11:1
  56. lcd.print(currentminute);
  57. lcd.setCursor(5, 1);//set cursor to partway through second row to print alarm time
  58. lcd.print("Alarm");//printAlarm hour:minute
  59. lcd.print(alarmhour);
  60. lcd.print(":");
  61. if(alarmminute<10){lcd.print(0);}//print 11:01 not 11:1
  62. lcd.print(alarmminute);
  63. if(currenthour==alarmhour&&currentminute==alarmminute){//if it is time for the alarm, perform the wake up function
  64. wakeup();
  65. }
  66. }
  67.  
  68. void enter_time(){ // has user set current time
  69. lcd.setCursor(place, 1);
  70. while(keeplooping){
  71. char key = keypad.getKey();
  72. if(key){
  73. if(hours==99){lcd.clear();}//if this is the first input, clear the screen of the prompt
  74. if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
  75. lcd.print(key);
  76. place++;//go to next space on lcd
  77. int input = key - '0';//get value as int
  78. if(hours == 99){hours = input;//set first digit if we haven't altered it yet
  79. }else{hours = ((10*hours)+input);}//or set second digit if we have
  80. }
  81. if(key==35){//done receiving inputs
  82. lcd.print(":");
  83. place++;
  84. keeplooping = false;//stop the input loop
  85. }
  86. }
  87. }
  88.  
  89. keeplooping = true;
  90. while(keeplooping){
  91. char key = keypad.getKey();
  92. if(key){
  93. if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
  94. lcd.print(key);
  95. place++;//go to next spot on lcd
  96. int input = key - '0';//get the input as an int
  97. if(minutes == 99){minutes = input;//set first digit of minutes if we haven't altered it yet
  98. }else{
  99. minutes = ((minutes*10)+input);//or set second digit if we have
  100. keeplooping = false;//leave the input loop
  101. }
  102. }
  103. }
  104. }
  105. }
  106. void enter_alarm_hour(){ //has user set alarm's hour
  107. lcd.setCursor(0, 1);
  108. keeplooping = true;
  109. while(keeplooping){
  110. char key = keypad.getKey();
  111. if(key){
  112. if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
  113. lcd.print(key);
  114. place++;//go to next spot on lcd
  115. int input = key - '0';//get the input as an int
  116. if(alarmhour == 99){alarmhour = input;//set first digit if we haven't altered it yet
  117. }else{alarmhour = ((10*alarmhour)+input);}//or set second digit if we have
  118. }
  119. if(key==35){//done receiving inputs
  120. lcd.print(":");
  121. place++;
  122. keeplooping = false;//stop the input loop
  123. }
  124. }
  125. }
  126. }
  127. void enter_alarm_minute(){ // has user enter alarm's minute
  128. keeplooping = true;
  129. while(keeplooping){
  130. char key = keypad.getKey();
  131. if(key){
  132. if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
  133. lcd.print(key);
  134. place++;//go to next spot on lcd
  135. int input = key - '0';//get the input as an int
  136. if(alarmminute == 99){alarmminute = input;//set first digit of minutes if we haven't altered it yet
  137. }else{
  138. alarmminute = ((alarmminute*10)+input);//or set second digit if we have
  139. keeplooping = false;//leave the input loop
  140. }
  141. }
  142. }
  143. }
  144. }
  145. void wakeup(){ //dump a cup of water(attached to the motor)
  146. if(second()<12){ //only dump water the first time that it is at the alarm time
  147. spin(4000);//dump water
  148. }
  149. }
  150. void spin(int duration){//spin motor for a duration in milliseconds
  151. digitalWrite(4, 1);//switch on current to motor
  152. digitalWrite(5, 1);
  153. digitalWrite(6, 1);
  154. digitalWrite(7, 18);
  155. delay(duration);
  156. digitalWrite(4,0);//switch off current to motor
  157. digitalWrite(5,0);
  158. digitalWrite(6, 0);
  159. digitalWrite(7, 0);
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement