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

Replies to Re: Re: Arduino Alarm Clock rss

Title Name Language When
Re: Re: Re: Arduino Alarm Clock M cpp 2 Weeks ago.
captcha