Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include<Keypad.h>
- #include<Time.h>
- #include <Servo.h>
- Servo myservo; //creates servo object to control servo
- LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //set up pins to lcd
- const byte ROWS = 4; //four rows on keypad
- const byte COLS = 4; //three columns on keypad
- char keys[ROWS][COLS] = {
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };
- byte rowPins[ROWS] = {30, 32, 34, 36}; //connect to the row pinouts of the keypad
- byte colPins[COLS] = {26, 24, 22, 38}; //connect to the column pinouts of the keypad
- Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
- int place = 0;
- int hours = 99;//set hours to 99 so we know if it has been altered
- int minutes = 99;//set minutes to 99 so we know if it has been altered
- boolean keeplooping = true;
- int alarmhour = 99;//set to 99 so we know if it has been altered
- int alarmminute = 99;//set to 99 se we know if it has been altered
- int currenthour;
- int currentminute;
- void setup(){
- myservo.attach(51); // attaches the servo on pin 51 to the servo object
- myservo.write(0);//make sure servo starts at 0 degrees
- lcd.begin(16,2);// set up the LCD's number of columns and rows
- lcd.print("Current Time");//prompt user for current timne
- lcd.setCursor(0, 1);//set to print on row 1(second row)
- lcd.print("hours # minutes");//tell user the input format
- enter_time(); //have user enter current time
- 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
- lcd.clear();
- lcd.print("Enter alarm time");
- enter_alarm_hour(); //have user set alarm time
- enter_alarm_minute();
- }
- void loop (){
- delay(10000);//check time every ten seconds
- currenthour = hour();//get hour
- currentminute = minute();//get minute
- lcd.clear();//clear screen
- lcd.print(currenthour);//print hour:minute
- lcd.print(":");
- if(currentminute<10){lcd.print(0);}//make it say 11:01 instead of 11:1
- lcd.print(currentminute);
- lcd.setCursor(5, 1);//set cursor to partway through second row to print alarm time
- lcd.print("Alarm");//printAlarm hour:minute
- lcd.print(alarmhour);
- lcd.print(":");
- if(alarmminute<10){lcd.print(0);}//print 11:01 not 11:1
- lcd.print(alarmminute);
- if(currenthour==alarmhour&¤tminute==alarmminute){//if it is time for the alarm, perform the wake up function
- wakeup();
- }
- }
- void enter_time(){ // has user set current time
- lcd.setCursor(place, 1);
- while(keeplooping){
- char key = keypad.getKey();
- if(key){
- if(hours==99){lcd.clear();}//if this is the first input, clear the screen of the prompt
- if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
- lcd.print(key);
- place++;//go to next space on lcd
- int input = key - '0';//get value as int
- if(hours == 99){hours = input;//set first digit if we haven't altered it yet
- }else{hours = ((10*hours)+input);}//or set second digit if we have
- }
- if(key==35){//done receiving inputs
- lcd.print(":");
- place++;
- keeplooping = false;//stop the input loop
- }
- }
- }
- keeplooping = true;
- while(keeplooping){
- char key = keypad.getKey();
- if(key){
- if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
- lcd.print(key);
- place++;//go to next spot on lcd
- int input = key - '0';//get the input as an int
- if(minutes == 99){minutes = input;//set first digit of minutes if we haven't altered it yet
- }else{
- minutes = ((minutes*10)+input);//or set second digit if we have
- keeplooping = false;//leave the input loop
- }
- }
- }
- }
- }
- void enter_alarm_hour(){ //has user set alarm's hour
- lcd.setCursor(0, 1);
- keeplooping = true;
- while(keeplooping){
- char key = keypad.getKey();
- if(key){
- if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
- lcd.print(key);
- place++;//go to next spot on lcd
- int input = key - '0';//get the input as an int
- if(alarmhour == 99){alarmhour = input;//set first digit if we haven't altered it yet
- }else{alarmhour = ((10*alarmhour)+input);}//or set second digit if we have
- }
- if(key==35){//done receiving inputs
- lcd.print(":");
- place++;
- keeplooping = false;//stop the input loop
- }
- }
- }
- }
- void enter_alarm_minute(){ // has user enter alarm's minute
- keeplooping = true;
- while(keeplooping){
- char key = keypad.getKey();
- if(key){
- if(key!=65&&key!=66&&key!=67&&key!=68&&key!=42&&key!=35){//make sure key is a number
- lcd.print(key);
- place++;//go to next spot on lcd
- int input = key - '0';//get the input as an int
- if(alarmminute == 99){alarmminute = input;//set first digit of minutes if we haven't altered it yet
- }else{
- alarmminute = ((alarmminute*10)+input);//or set second digit if we have
- keeplooping = false;//leave the input loop
- }
- }
- }
- }
- }
- void wakeup(){ //dump a cup of water(attached to the servo)
- for(int pos=0; pos<110; pos+=1){ //go from 0 degrees to 110 degrees
- myservo.write(pos); //put the servo at the new position
- delay(15); //give it 15 ms to reach new position
- }
- delay(5000); // give it 5 seconds for all of the water to drain out
- for(int pos=110; pos>0; pos-=1){ //go from 110 degrees back to 0 degrees
- myservo.write(pos); //put the servo at the new position
- delay(15); //give it 15 ms to reach new position
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement