Итак, я написал некоторый код, который я хочу начать мигать светодиодом, когда время достигает определенного момента каждый день. Светодиод должен продолжать мигать до тех пор, пока не будет нажата кнопка, однако по какой-то причине светодиод перестанет мигать сам по себе, обычно примерно через 1 минуту.
Я не уверен, активируется ли контакт 11 случайным образом или он просто не включает свет после того, как состояние таймера прошло. Ребята, вы знаете, где я ошибаюсь?
#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
bool active = false;
void setup()
{
// Setup Serial connection
Serial.begin(115200);
// Uncomment the next line if you are using an Arduino Leonardo
//while (!Serial) {}
// Initialize the rtc object
rtc.begin();
pinMode(12, OUTPUT);
pinMode(11, INPUT);
// The following lines can be uncommented to set the date and time
// rtc.setDOW(MONDAY); // Set Day-of-Week to SUNDAY
// rtc.setTime(15, 51, 0); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(9, 11, 2017); // Set the date to January 1st, 2014
}
void loop()
{
int hour = rtc.getTime().hour;
int min = rtc.getTime().min;
// Send time
Serial.print(hour);
Serial.print(":");
Serial.print(min);
Serial.println(" ");
if(hour == 10 && min == 38) {
active = true;
}
blinker();
}
void blinker() {
while(active == true) {
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(1000);
buttonCheck();
}
}
void buttonCheck() {
if(digitalRead(11) == 1) {
Serial.println("Button pushed");
active = false;
}
}