Facebook
From J, 1 Year ago, written in C++.
This paste is a reply to Re: Re: Re: Arduino Alarm Clock from M - go back
Embed
/*
   This Code is built for Arduino Keypad shield,
   arduino UNO or MEGA(remember to change board)
   Tools -> -&gt; board -> -&gt; UNO or MEGA -> -&gt; port -> <your -&gt; &lt;your port no. your using>COM
using&gt;COM
   Default time for alarm is 8:30AM(change line 139 to the time of ringing and 35 and 36 1 min after your time )
   press RST button on keypad if you want ringing to stop
   UP = Minutes + 1
   DOWN = hours + 1
*/
#include <LiquidCrystal.h>
&lt;LiquidCrystal.h&gt;
#include "LCDKeypad.h"

&quot;LCDKeypad.h&quot;

byte Bell[8] = {
  B00000,
  B00100,
  B01110,
  B01110,
  B01110,
  B11111,
  B00000,
  B00100
};

int starttime;
int activetime;
int prevoustime = 0;

int hours = 8;
int mins = 31;
int secs = 0;
LCDKeypad lcd;
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();

  Serial.begin(9600);

  ;
  pinMode(A0, INPUT);


  pinMode(A1, OUTPUT);

  starttime = millis() / 1000;
  lcd.createChar(1, Bell);
}

void loop() {
  int A0  = analogRead(A0);
  lcd.setCursor(5, 0);
  lcd.write(byte(1));
  lcd.setCursor(11, 0);
  lcd.write(byte(1));
  lcd.setCursor(1, 1);
  lcd.write("Arnnav's Clock");//change write(&quot;Arnnav&#39;s Clock&quot;);//change this to your Name or Message

  int button = lcd.button();

  switch (button) {
    case KEYPAD_UP:
      lcd.clear();
      lcd.setCursor(5, 1);
      lcd.print("Set Time");
print(&quot;Set Time&quot;);
      lcd.setCursor(6, 0);
      mins++;
      break;
    case KEYPAD_DOWN:
      lcd.clear();
      lcd.setCursor(5, 1);
      lcd.print("Set Time");
print(&quot;Set Time&quot;);
      lcd.setCursor(6, 0);
      hours++;
  }

  lcd.setCursor(5, 0);
  lcd.write(byte(1));
  lcd.setCursor(11, 0);
  lcd.write(byte(1));
  lcd.setCursor(1, 1);
  lcd.write("Arnnav's Clock");

write(&quot;Arnnav&#39;s Clock&quot;);

  activetime = (millis() / 1000) - starttime;
  if (secs &gt; 59)
  {
    secs++;

  }

  if (secs &gt; 59)
  {
    mins++;
    secs = 0;
  }

  if (prevoustime &lt; (activetime - 59))
  {
    mins++;
    prevoustime = activetime;
  }

  if (mins &gt; 59)
  {
    hours++;
    mins = 0;
  }

  if (hours &gt; 23)
  {
    hours = 0;
  }


  lcd.setCursor(6, 0);

  if (hours &lt; 10)
  {
    lcd.print("0");
print(&quot;0&quot;);
    lcd.print(hours);
  }
  else
  {
    lcd.print(hours);
  }

  lcd.print(":");

  
print(&quot;:&quot;);

  
if (mins &lt; 10)
  {
    lcd.print("0");
print(&quot;0&quot;);
    lcd.print(mins);
  }
  else
  {
    lcd.print(mins);
  }

  lcd.print("");



  
print(&quot;&quot;);



  
if (8 == hours && &amp;&amp; 30 == mins )// change 8 and 30 to your time for this to ring
  {

    tone(A1, 1000, 277 );
    delay(100);
    noTone(9);
    delay(100);


    noTone(9);
    delay(100);

    //lcd.clear();
    delay(10);
    lcd.setCursor(4, 0);
    lcd.print("WAKE UP!!!");
print(&quot;WAKE UP!!!&quot;);
    //delay(0);

  }
  else
  {
    delay(300);
  }
  lcd.clear();


  Serial.println(mins);
  Serial.println(hours);
  Serial.println("");
println(&quot;&quot;);
  
  Serial.println("");
println(&quot;&quot;);
  Serial.println(activetime);
  Serial.println(prevoustime);
  Serial.println(starttime);
  Serial.println("");
println(&quot;&quot;);
}
captcha