0

well I get task to make school project alarm clock using arduino, xd as you can see im not very good at it i mean i know something but not everything so please can someone help me, i copied this code somewhere from net and i do little changes on it but there is only thing i cant get right, i just want to add when i press button it stop alarm from beeping, now it beeps until, for example i set alarm on 08:05 it will ring until 08:06, my question is how can i make that when i press button alarm goes off , can someone give me some tips i would be really grateful

i copied original code from here: http://roboticadiy.com/how-to-make-arduino-alarm-clock/

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <DS1302.h>
int Hour;
int Min;
int pset = 8; // pushbutton for setting alarm
int phour = 9; // pushbutton for hour
int pmin = 10; // pushbutton for minutes
int pexit = 11; // pushbutton for exit of set alarm
int buzzer = 6;
int h;
int m;
int buttonforset = 0; // pushbutton state for setting alarm
int buttonforhour = 0; // pushbutton state for hour
int buttonformin = 0;// pushbutton state for minutes
int buttonforexit = 0;// pushbutton state for exit of set alarm
int activate=0;
 Time t;

// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
 pinMode(pset, INPUT);
 pinMode(phour, INPUT);
 pinMode(pmin, INPUT);
 pinMode(pexit, INPUT);
 // Set the clock to run-mode, and disable the write protection
 rtc.halt(false);
 rtc.writeProtect(false);

 // Setup LCD to 16x2 characters
 lcd.begin();

// The following lines can be commented out to use the values already stored in the DS1302
 //rtc.setDOW(SATURDAY); // Set Day-of-Week to FRIDAY
 //rtc.setTime(10, 0, 0); // Set the time to 12:00:00 (24hr format)
 //rtc.setDate(11, 11, 2017); // Set the date to August 6th, 2010
}

void loop()
{
 if (activate == 0) {

// Display time on the right conrner upper line
 lcd.setCursor(0, 0);
 lcd.print("Time: ");
 lcd.setCursor(6, 0);
 lcd.print(rtc.getTimeStr());
 
 // Display abbreviated Day-of-Week in the lower left corner
 //lcd.setCursor(0, 1);
 //lcd.print(rtc.getDOWStr(FORMAT_SHORT));
 
 // Display date in the lower right corner
 lcd.setCursor(0, 1);
 lcd.print("Date: ");
 lcd.setCursor(6, 1);
 lcd.print(rtc.getDateStr());
 t = rtc.getTime();
 Hour = t.hour;
 Min = t.min;
 buttonforset = digitalRead(pset);
 } // setting button pressed
 if (buttonforset == HIGH) {
 activate =1;
 lcd.clear(); }
 while(activate== 1){
 lcd.setCursor(0,0);
 lcd.print("Set Alarm");
 lcd.setCursor(0,1);
 lcd.print("Hour= ");
 lcd.setCursor(9,1);
 lcd.print("Min= ");
 buttonforhour = digitalRead(phour); // set hour for alarm
 if (buttonforhour == HIGH){
 h++;
 lcd.setCursor(5,1);
 lcd.print(h);
 if (h>23){ 
 h=0;
 lcd.clear(); }
 delay(100); 
 }
 buttonformin = digitalRead(pmin); // set minutes for alarm
 if (buttonformin == HIGH){
 m++;
 lcd.setCursor(13,1);
 lcd.print(m);
 if (m>59){
 m=0; 
 lcd.clear();}
 delay(100); 
 }

lcd.setCursor(5,1);
 lcd.print(h);
 lcd.setCursor(13,1);
 lcd.print(m);
 buttonforexit = digitalRead(pexit); // exit from set alarm mode
 if (buttonforexit == HIGH){
 activate = 0;
 lcd.clear();
 lcd.print("Postavljanje"); 
 lcd.setCursor(0,1);
 lcd.print("alarma..."); 
 delay(2000);
 lcd.clear();
   }
 }
 
 if (Hour== h && Min== m) {
 lcd.clear();
 lcd.print("Budenje...");
 tone(6,5000);
 delay(1000);
 noTone(6);}
 
}

4
  • well its not actually problem everything works fine but i just want to add when i press button it stop alarm from beeping, now it beeps until for example i set alarm on 08:05 it will ring until 08:06 my question is how can i make that when i press button alarm goes off – cukoloda1234 Mar 19 at 21:45
  • xd yea i know im noob on this site i tried to post it here but it just mess up it doesnt write in lines like i Arduino Ide – cukoloda1234 Mar 19 at 21:46
  • here is original code roboticadiy.com/how-to-make-arduino-alarm-clock – cukoloda1234 Mar 19 at 21:50
  • use a flag to enable the alarm sound ... clear flag with a timer ... also clear the flag when button is pressed ... here is an example of how to use a flag variable ... arduino.stackexchange.com/questions/81738/… – jsotola Mar 19 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.