#define ALR_PIN 10 //set
#define PULLUP true //aktifkan
#define INVERT true //If invert ==true,HIGH=released,LOW=pressed
#define DEBOUNCE_MS 20 //state react with button
#define REPEAT_FIRST 500 //state untuk tekan berapa lama button
#define REPEAT_INCR 100 // increase kan number
//Declare push buttons
Button btnDN(DN_PIN, PULLUP, INVERT, DEBOUNCE_MS); //set 1st button utk decrement
Button btnUP(UP_PIN, PULLUP, INVERT, DEBOUNCE_MS); //set 2nd button utk increment
Button btnSET(SET_PIN, PULLUP, INVERT, DEBOUNCE_MS); //set button utk function timer
Button btnALR(ALR_PIN, PULLUP, INVERT, DEBOUNCE_MS); //set button utk function alarm
enum {WAIT, INCR, DECR}; //The possible states for the state machine
uint8_t STATE; //The current state machine state
int count; //The number that is adjusted
int lastCount = -1; //Previous value of count (initialized to ensure it's different when the sketch starts)
unsigned long rpt = REPEAT_FIRST; //A variable time that is used to drive the repeats for long presses
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
pinMode(buzzer,OUTPUT);
rtc.begin();
lcd.setCursor(0,0);
lcd.print("Welcome Shaqib!");
delay(2000);
lcd.clear();
//rtc.setTime(12,24,00);
}
void loop() {
t=rtc.getTime();
hh=t.hour,DEC;
mm=t.min,DEC;
ss=t.sec,DEC;
btnSET.read();
btnUP.read();
btnDN.read();
btnALR.read();
if(setMode==0 && setAlarm==0 ){
tunjukJamTemp();
tunjukTimer();}
if(setMode!=0 && setAlarm==0 && alarmMode==0 ){delay(100);}
if(setMode==1 && setAlarm==0 && alarmMode==0 ){lcd.setCursor(7,1);lcd.print(" ");delay(100);tunjukJamTemp();tunjukTimer();}
if(setMode==2 && setAlarm==0 && alarmMode==0 ){lcd.setCursor(10,1);lcd.print(" ");delay(100);tunjukJamTemp();tunjukTimer();}
if(setMode==3 && setAlarm==0 && alarmMode==0 ){lcd.setCursor(13,1);lcd.print(" ");delay(100);tunjukJamTemp();tunjukTimer();}
if(setMode==4 && setAlarm==0 && alarmMode==0 ){tunjukJamTemp();tunjukTimer();stepDown();delay(1000);}
if(setMode==0 && setAlarm!=0 && alarmMode==0 ){delay(100);}
if(setMode==0 && setAlarm==2 && alarmMode==0 ){lcd.setCursor(0,0);lcd.print(" ");delay(100); lcd.setCursor(0,0);
if(alarmHH<10){lcd.print("0");}
lcd.print(alarmHH);lcd.print(":");
if(alarmMM<10){lcd.print("0");}
lcd.print(alarmMM);lcd.print(":");
if(alarmSS<10){lcd.print("0");}
lcd.print(alarmSS);lcd.setCursor(0,1);
lcd.print("Set Your Alarm");}
if(setMode==0 && setAlarm==3 && alarmMode==0 ){lcd.setCursor(3,0);lcd.print(" ");delay(100); lcd.setCursor(0,0);
if(alarmHH<10){lcd.print("0");}
lcd.print(alarmHH);lcd.print(":");
if(alarmMM<10){lcd.print("0");}
lcd.print(alarmMM);lcd.print(":");
if(alarmSS<10){lcd.print("0");}
lcd.print(alarmSS);lcd.setCursor(0,1);
lcd.print("Set Your Alarm");}
if(setMode==0 && setAlarm==4 && alarmMode==0 ){lcd.setCursor(6,0);lcd.print(" ");delay(100); lcd.setCursor(0,0);
if(alarmHH<10){lcd.print("0");}
lcd.print(alarmHH);lcd.print(":");
if(alarmMM<10){lcd.print("0");}
lcd.print(alarmMM);lcd.print(":");
if(alarmSS<10){lcd.print("0");}
lcd.print(alarmSS);lcd.setCursor(0,1);
lcd.print("Set Your Alarm");}
if(setMode==0 && setAlarm==5 && alarmMode==0 ){alarmMode=1;setAlarm=0;}
setupAlarm();
Alarm(alarmHH,alarmMM);
btnSET.read();
btnUP.read();
btnDN.read();
btnALR.read();
switch (STATE) {
case WAIT:
if (btnSET.wasPressed())
{ setMode = setMode+1;}
if (btnALR.wasPressed())
{ setAlarm = setAlarm+1;}
if (btnUP.wasPressed())
STATE = INCR;
else if (btnDN.wasPressed())
STATE = DECR;
else if (btnUP.wasReleased())
rpt = REPEAT_FIRST;
else if (btnDN.wasReleased())
rpt = REPEAT_FIRST;
else if (btnUP.pressedFor(rpt)) {
rpt += REPEAT_INCR;
STATE = INCR;
}
else if (btnDN.pressedFor(rpt)) {
rpt += REPEAT_INCR;
STATE = DECR;
}
break;
case INCR:
if (setMode==1 && setAlarm==0 && alarmMode==0 && timerhh<23)timerhh=timerhh+1;
if (setMode==2 && setAlarm==0 && alarmMode==0 && timermm<59)timermm=timermm+1;
评论0