SHARE
TWEET

Final Project

jmyean May 17th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. // write if functions for all
  4.  
  5. #include <virtuabotixRTC.h> //Library used
  6. #include <LiquidCrystal_I2C.h>
  7. LiquidCrystal_I2C lcd(0x3F, 16, 2);
  8. #include <Wire.h>
  9. #include <DS1302.h>
  10. virtuabotixRTC myRTC(4, 3, 2);
  11. int pset = 8; // pushbutton for setting alarm
  12. int phour = 9; // pushbutton for hour
  13. int pmin = 10; // pushbutton for minutes
  14. int pexit = 11; // pushbutton for exit of set alarm
  15. int buzzer = 6;
  16. const byte LedPin = 7;
  17. int h;
  18. int m;
  19. int buttonforset = 0; // pushbutton state for setting alarm
  20. int buttonforhour = 0; // pushbutton state for hour
  21. int buttonformin = 0;// pushbutton state for minutes
  22. int buttonforexit = 0; // pushbutton state for exit of set alarm
  23. int activate = 0;
  24. Time t;
  25.  
  26. void setup()
  27. {
  28.   pinMode(pset, INPUT);
  29.   pinMode(phour, INPUT);
  30.   pinMode(pmin, INPUT);
  31.   pinMode(pexit, INPUT);
  32.   pinMode(LedPin, OUTPUT);
  33.  
  34.   Serial.begin(9600);
  35.   lcd.begin();
  36.  
  37.   // Set the current date, and time in the following format:
  38.   // seconds, minutes, hours, day of the week, day of the month, month, year
  39.   myRTC.setDS1302Time(0, 11, 11, 5, 18, 5, 2019); //Here you write your actual time/date as shown above
  40.   //but remember to "comment/remove" this function once you're done
  41.   //The setup is done only one time and the module will continue counting it automatically
  42. }
  43.  
  44. void loop() {
  45.   // This allows for the update of variables for time or accessing the individual elements.
  46.   myRTC.updateTime();
  47.  
  48.   // Start printing elements as individuals
  49.   lcd.setCursor(0, 0);
  50.   lcd.print("Time: ");
  51.  
  52.   lcd.setCursor(5, 1);
  53.   lcd.print(" ");
  54.  
  55.   lcd.setCursor(0, 1);
  56.   lcd.print("Date: ");
  57.  
  58.   lcd.setCursor (9, 1);
  59.   lcd.print(myRTC.dayofmonth);
  60.  
  61.   lcd.setCursor (8, 1);
  62.   lcd.print("/");
  63.  
  64.  
  65.   lcd.setCursor (6, 1);
  66.   if (myRTC.month > 9)
  67.   {
  68.   lcd.print(myRTC.month);
  69.   }
  70.   else
  71.   {
  72.    lcd.setCursor (7, 1);
  73.    lcd.print(myRTC.month);
  74.   }
  75.  
  76.   lcd.setCursor (11, 1);
  77.   lcd.print("/");
  78.  
  79.   lcd.setCursor (12, 1);
  80.   lcd.print(myRTC.year);
  81.  
  82.   lcd.setCursor(5, 0);
  83.   lcd.print(" ");
  84.  
  85. lcd.setCursor (6, 0);
  86.   if (myRTC.hours > 9)
  87.   {
  88.   lcd.print(myRTC.hours);
  89.   }
  90.   else
  91.   {
  92.    lcd.setCursor (7, 0);
  93.    lcd.print(myRTC.hours);
  94.   }
  95.  
  96.   lcd.setCursor(8, 0);
  97.   lcd.print(":");
  98.  
  99. lcd.setCursor (9, 0);
  100.   if (myRTC.minutes > 9)
  101.   {
  102.   lcd.print(myRTC.minutes);
  103.   }
  104.   else
  105.   {
  106.    lcd.setCursor (10, 0);
  107.    lcd.print(myRTC.minutes);
  108.    lcd.setCursor (9, 0);
  109.    lcd.print("0");
  110.   }
  111.  
  112.   lcd.setCursor(11, 0);
  113.   lcd.print(":");
  114.  
  115.   lcd.setCursor(12, 0);
  116.   if (myRTC.seconds > 9)
  117.   {
  118.     lcd.println(myRTC.seconds);
  119.   }
  120.   else
  121.   {
  122.     lcd.setCursor(13, 0);
  123.     lcd.println(myRTC.seconds);
  124.     lcd.setCursor(12, 0);
  125.     lcd.print("0");
  126.   }
  127.  
  128.   lcd.setCursor(14, 0);
  129.   lcd.print(" ");
  130.   lcd.setCursor(15, 0);
  131.   lcd.print(" ");
  132.   // Delay so the program doesn't print non-stop
  133.   delay(1000);
  134.  
  135.  
  136.   buttonforset = digitalRead(pset);
  137.   // setting button pressed
  138.   if (buttonforset == HIGH)
  139.   {
  140.     activate = 1;
  141.     lcd.clear();
  142.   }
  143.   while (activate == 1) {
  144.     lcd.setCursor(0, 0);
  145.     lcd.print("Set Alarm");
  146.     lcd.setCursor(0, 1);
  147.     lcd.print("Hour= ");
  148.     lcd.setCursor(9, 1);
  149.     lcd.print("Min= ");
  150.     buttonforhour = digitalRead(phour); // set hour for alarm
  151.     if (buttonforhour == HIGH)
  152.     {
  153.       h++;
  154.       lcd.setCursor(5, 1);
  155.       lcd.print(h);
  156.  
  157.       if (h > 23)
  158.       {
  159.         h = 0;
  160.         lcd.clear();
  161.       }
  162.  
  163.  
  164.       delay(100);
  165.     }
  166.  
  167.     buttonformin = digitalRead(pmin); // set minutes for alarm
  168.     if (buttonformin == HIGH)
  169.     {
  170.       m++;
  171.       lcd.setCursor(13, 1);
  172.       lcd.print(m);
  173.  
  174.       if (m > 59)
  175.       {
  176.         m = 0;
  177.         lcd.clear();
  178.       }
  179.  
  180.       delay(100);
  181.     }
  182.  
  183.     lcd.setCursor(5, 1);
  184.     lcd.print(h);
  185.     lcd.setCursor(13, 1);
  186.     lcd.print(m);
  187.     buttonforexit = digitalRead(pexit); // exit from set alarm mode
  188.     if (buttonforexit == HIGH) {
  189.       activate = 0;
  190.       lcd.clear();
  191.     }
  192.  
  193.    if (myRTC.hours == h && myRTC.minutes == m)
  194.     {
  195.       tone(6, 400, 300);
  196.     }
  197.     delay (500);
  198.  
  199.  
  200.     if (myRTC.hours == h && myRTC.minutes == m)
  201.     {
  202.       digitalWrite(LedPin, HIGH);
  203.       delay(300);
  204.       digitalWrite(LedPin, LOW);
  205.       delay(300);
  206.     }
  207.   }
  208. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top