Facebook
From Arnnav Kudale, 5 Years ago, written in C++.
This paste is a reply to Arduino Alarm Clock from Arnnav Kudale - view diff
Embed
Download Paste or View Raw
Hits: 173
  1. /*
  2.    This Code is built for Arduino Keypad shield,
  3.    arduino UNO or MEGA(remember to change board)
  4.    Tools -> board -> UNO or MEGA -> port -> <your port no. your using>COM
  5.    Default time for alarm is 8:30AM(change line 139 to the time of ringing and 35 and 36 1 min after your time )
  6.    press RST button on keypad if you want ringing to stop
  7.    UP = Minutes + 1
  8.    DOWN = hours + 1
  9. */
  10. #include <EEPROM.h>
  11. #include <LiquidCrystal.h>
  12. #include "LCDKeypad.h"
  13. int addr = 0;
  14. int addrs = 1;
  15. byte Bell[8] = {
  16.   B00000,
  17.   B00100,
  18.   B01110,
  19.   B01110,
  20.   B01110,
  21.   B11111,
  22.   B00000,
  23.   B00100
  24. };
  25.  
  26. int starttime;
  27. int activetime;
  28. int prevoustime = 0;
  29.  
  30. int hours ;
  31. int mins ;
  32. int secs = 0;
  33. LCDKeypad lcd;
  34. void setup()
  35. {
  36.  
  37.   hours = EEPROM.put(addr,hours);
  38.   mins = EEPROM.put(addrs,mins);
  39.   lcd.begin(16, 2);
  40.   lcd.clear();
  41.  
  42.   Serial.begin(9600);
  43.  
  44.   ;
  45.   pinMode(A0, INPUT);
  46.  
  47.  
  48.   pinMode(A1, OUTPUT);
  49.  
  50.   starttime = millis() / 1000;
  51.   lcd.createChar(1, Bell);
  52. }
  53.  
  54. void loop() {
  55.  int hours = EEPROM.put(addr,hours);
  56.   int mins = EEPROM.put(addrs,mins);
  57.   int A0  = analogRead(A0);
  58.   lcd.setCursor(5, 0);
  59.   lcd.write(byte(1));
  60.   lcd.setCursor(11, 0);
  61.   lcd.write(byte(1));
  62.   lcd.setCursor(1, 1);
  63.   lcd.write("Arnnav's Clock");//change this to your Name or Message
  64.  
  65.   int button = lcd.button();
  66.  
  67.   switch (button) {
  68.     case KEYPAD_UP:
  69.       lcd.clear();
  70.       lcd.setCursor(5, 1);
  71.       lcd.print("Set Time");
  72.       lcd.setCursor(6, 0);
  73.       mins++;
  74.       break;
  75.     case KEYPAD_DOWN:
  76.       lcd.clear();
  77.       lcd.setCursor(5, 1);
  78.       lcd.print("Set Time");
  79.       lcd.setCursor(6, 0);
  80.       hours++;
  81.   }
  82.  
  83.   lcd.setCursor(5, 0);
  84.   lcd.write(byte(1));
  85.   lcd.setCursor(11, 0);
  86.   lcd.write(byte(1));
  87.   lcd.setCursor(1, 1);
  88.   lcd.write("Arnnav's Clock");
  89.  
  90.   activetime = (millis() / 1000) - starttime;
  91.   if (secs > 59)
  92.   {
  93.     secs++;
  94.  
  95.   }
  96.  
  97.   if (secs > 59)
  98.   {
  99.     mins++;
  100.     secs = 0;
  101.   }
  102.  
  103.   if (prevoustime < (activetime - 59))
  104.   {
  105.     mins++;
  106.     prevoustime = activetime;
  107.   }
  108.  
  109.   if (mins > 59)
  110.   {
  111.     hours++;
  112.     mins = 0;
  113.   }
  114.  
  115.   if (hours > 23)
  116.   {
  117.     hours = 0;
  118.   }
  119.  
  120.  
  121.   lcd.setCursor(6, 0);
  122.  
  123.   if (hours < 10)
  124.   {
  125.     lcd.print("0");
  126.     lcd.print(hours);
  127.   }
  128.   else
  129.   {
  130.     lcd.print(hours);
  131.   }
  132.  
  133.   lcd.print(":");
  134.  
  135.   if (mins < 10)
  136.   {
  137.     lcd.print("0");
  138.     lcd.print(mins);
  139.   }
  140.   else
  141.   {
  142.     lcd.print(mins);
  143.   }
  144.  
  145.   lcd.print("");
  146.  
  147.  
  148.  
  149.   if (8 == hours && 30 == mins )// change 8 and 30 to your time for this to ring
  150.   {
  151.  
  152.     tone(A1, 1000, 277 );
  153.     delay(100);
  154.     noTone(9);
  155.     delay(100);
  156.  
  157.  
  158.     noTone(9);
  159.     delay(100);
  160.  
  161.     //lcd.clear();
  162.     delay(10);
  163.     lcd.setCursor(4, 0);
  164.     lcd.print("WAKE UP!!!");
  165.     //delay(0);
  166.  
  167.   }
  168.   else
  169.   {
  170.     delay(300);
  171.   }
  172.   lcd.clear();
  173.  
  174.  
  175.   Serial.println(mins);
  176.   Serial.println(hours);
  177.   Serial.println("");
  178.  
  179.   Serial.println(activetime);
  180.   Serial.println(prevoustime);
  181.   Serial.println(starttime);
  182.   Serial.println("");
  183.    EEPROM.put(addr,hours);
  184.    EEPROM.put(addrs,mins);
  185. }
captcha