arduino budik
Napsal: 04 úno 2019, 18:42
Zdravim, mam problem s budekem a to sice takoví, ze kdyz mi budik zvoni tak prestane zvonit jen kdyz drzim tlacitko exit a když jej pustim tak zase zvoni. Zkousel sem pridat delay, ale to delalo neplechu.Tlacitko exit je pouzivano pro prepnuti z5 z nastavovaní budiku a pro zruseni alarmu. Za každkou pomoc předem děkuji.
Kód: Vybrat vše
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
byte c_hacek[8] = {
0b01010,
0b00100,
0b01110,
0b10000,
0b10000,
0b10000,
0b01110,
0b00000
};
byte y_carka[8] = {
0b00010,
0b00100,
0b10001,
0b10001,
0b01111,
0b00001,
0b01110,
0b00000
};
byte i_carka[8] = {
0b00010,
0b00100,
0b00000,
0b00100,
0b01100,
0b00100,
0b01110,
0b00000
};
LiquidCrystal_I2C lcd(0x27, 20, 4);
#include <DS1302.h>
int Hour;
int Min;
int Sec;
int pset = 22;
int phour = 23;
int pmin = 24;
int pexit = 25;
int buzzer = 8;
int h;
int m;
int buttonforset = 0;
int buttonforhour = 0;
int buttonformin = 0;
int buttonforexit = 0;
int buttonforstopbuzz = 0;
int activate=0;
int budik=0;
Time t;
DS1302 rtc(7, 6, 5);
void setup()
{
pinMode(pset, INPUT);
pinMode(phour, INPUT);
pinMode(pmin, INPUT);
pinMode(pexit, INPUT);
rtc.halt(false);
rtc.writeProtect(false);
lcd.begin();
rtc.setDOW(SUNDAY);
rtc.setTime(20, 9, 45);
rtc.setDate(27, 1, 2019);
}
void loop()
{
lcd.createChar(0, c_hacek);
lcd.setCursor(0, 0);
lcd.write(byte(0));
lcd.print("as: ");
lcd.setCursor(5, 0);
lcd.print(rtc.getTimeStr());
lcd.setCursor(0, 2);
lcd.print("Den v t");
lcd.createChar(1, y_carka);
lcd.setCursor(7, 2);
lcd.write(byte(1));
lcd.setCursor(8, 2);
lcd.print("dnu: ");
lcd.setCursor(13, 2);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));
lcd.setCursor(0, 1);
lcd.print("Datum: ");
lcd.setCursor(7, 1);
lcd.print(rtc.getDateStr());
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
Sec = t.sec;
buttonforexit = digitalRead(pexit);
if (activate == 0) {
buttonforset = digitalRead(pset);
}
if (buttonforset == HIGH) {
activate =1;
lcd.clear(); }
while(activate== 1){
lcd.setCursor(0,0);
lcd.print("Nastaven");
lcd.createChar(2, i_carka);
lcd.setCursor(8,0);
lcd.write(byte(2));
lcd.setCursor(10,0);
lcd.print("bud");
lcd.setCursor(13,0);
lcd.write(byte(2));
lcd.setCursor(14,0);
lcd.print("ku");
lcd.setCursor(0,1);
lcd.print("Hour= ");
lcd.setCursor(9,1);
lcd.print("Min= ");
buttonforhour = digitalRead(phour);
if (buttonforhour == HIGH){
h++;
lcd.setCursor(5,1);
lcd.print(h);
if (h>23){
h=0;
lcd.clear(); }
delay(100);
}
buttonformin = digitalRead(pmin);
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);
if (buttonforexit == HIGH){
activate = 0;
lcd.clear();
}
}
if (activate == 0) {
if (Hour== h && Min== m && buttonforexit == LOW ) {
tone(buzzer,400);
}
buttonforstopbuzz = digitalRead(pexit);{
}
if (buttonforstopbuzz == HIGH) {
digitalRead(buttonforstopbuzz=HIGH);
noTone(buzzer);
delay(60000);
}
}
}