Facebook
From Arnnav Kudale, 4 Years ago, written in C++.
This paste is a reply to Re: Arduino Alarm Clock from Arnnav Kudale - go back
Embed
Viewing differences between Re: Arduino Alarm Clock and Re: Re: Arduino Alarm Clock
/*
   This Code is built for Arduino Keypad shield,
   arduino UNO or MEGA(remember to change board)
   Tools -> board -> UNO or MEGA -> port -> 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 
#include "LCDKeypad.h"

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 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");
      lcd.setCursor(6, 0);
      mins++;
      break;
    case KEYPAD_DOWN:
      lcd.clear();
      lcd.setCursor(5, 1);
      lcd.print("Set Time");
      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");

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

  }

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

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

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

  if (hours > 23)
  {
    hours = 0;
  }


  lcd.setCursor(6, 0);

  if (hours < 10)
  {
    lcd.print("0");
    lcd.print(hours);
  }
  else
  {
    lcd.print(hours);
  }

  lcd.print(":");

  if (mins < 10)
  {
    lcd.print("0");
    lcd.print(mins);
  }
  else
  {
    lcd.print(mins);
  }

  lcd.print("");



  if (8 == hours && 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!!!");
    //delay(0);

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


  Serial.println(mins);
  Serial.println(hours);
  Serial.println("");
  Serial.println(amins);\n  Serial.println(ahours);\n  
  Serial.println("");
  Serial.println(activetime);
  Serial.println(prevoustime);
  Serial.println(starttime);
  Serial.println("");
}

Replies to Re: Re: Arduino Alarm Clock rss

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