pin 2 is for turning on and off at sepecified time... pin 3 is for turning on the light whrn button is pressed and turned off automatically as time decided in the program... pin 4 is for turning off the light after button is pressed and light will be on as time decided..... the problem is... i cant store the button press time in x and y for continuing the loop. how can i store it...
const int light = 13; int y1; int y2; int y3; int x1; int x2; int x3; int hour1 = 16; int min1 = 43; int sec1 = 0; int hour2 = 4 ; int min2 = 43; int sec2 = 0; int hour3 = 15 ; int min3 = 43; int sec3 = 0; int buttonState1 = 0; int buttonState2 = 0; int buttonState3 = 0; RTC_DS1307 rtc;
void setup() {
Serial.begin(9600); Wire.begin(); rtc.begin();
pinMode(light, OUTPUT); pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP);
}
void loop() { DateTime now = rtc.now(); buttonState1 = digitalRead(2); if ( buttonState1 == LOW) { if (now.hour() == hour1 && now.minute() == min1 && now.second() == sec1) { digitalWrite(light, HIGH); } if (now.hour() == hour2 && now.minute() == min2 && now.second() == sec2) { digitalWrite(light, LOW); } } buttonState3 = digitalRead(4); if (buttonState3 == LOW) { int y1 = now.hour(); int y2 = now.minute(); int y3 = now.second(); if (now.hour() == y1 && now.minute() == y2 && now.second() == y3) { digitalWrite(light, LOW); }
if (now.hour() == hour3 && now.minute() == min3 && now.second() == sec3)
{
digitalWrite(light, HIGH);
}
} buttonState2 = digitalRead(3); if (buttonState2 == LOW) { int x1 = now.hour(); int x2 = now.minute(); int x3 = now.second(); if (now.hour() == x1 && now.minute() == x2 && now.second() == x3) { digitalWrite(light, HIGH); }
if (now.hour() == hour2 && now.minute() == min2 && now.second() == sec2)
{
digitalWrite(light, LOW);
}
} }