hello guys ....i uploaded some questions earlier but this time i got one step forward and reach to the end of my coding. the code is
#include <Arduino.h>
#include <Wire.h>
#include <RTClib.h>
const int light = 13;
int y1;
int y2;
int y3;
int z1;
int z2;
int z3;
int k1;
int k2;
int k3;
int buttonState1;
int buttonState2;
int buttonState3;
const int buttonPin[] = {2, 3, 4};
int buttonState = 0;
RTC_DS1307 rtc;
void setup()
{
Serial.begin(9600);
Wire.begin();
rtc.begin();
k1 = 0;
k2 = 0;
k3 = 0;
buttonState1 = 1;
buttonState2 = 1;
buttonState3 = 1;
pinMode(light, OUTPUT);
for (int x = 0; x < 3; x++)
{
pinMode(buttonPin[x], INPUT);
}
}
void RESET()
{
DateTime now = rtc.now();
if (now.hour() == 2 && now.minute() == 27 && now.second() == 0)
{
digitalWrite(light, HIGH);
}
if (now.hour() == 14 && now.minute() == 34 && now.second() == 0)
{
digitalWrite(light, LOW);
}
k1 = 1;
}
void loop() {
DateTime now = rtc.now();
while (1)
{
buttonState1 = digitalRead(2);
if (buttonState1 == LOW)
{
k1 = 1;
}
if (k1 == 1)
RESET();
buttonState2 = digitalRead(3);
if (buttonState2 == LOW )
{ int z1 = now.hour();
int z2 = now.minute();
int z3 = now.second();
digitalWrite(light, HIGH);
k2 = 1;
k1 = 0;
k3 = 0;
}
if (k2 == 1)
{
DateTime now = rtc.now();
if (now.hour() == 5 && now.second() ==0)
{
digitalWrite(light, LOW);
}
if (now.hour() == z1 && now.second() == z3 )
{
digitalWrite(light, HIGH);
}
k2 = 1;
}
buttonState3 = digitalRead(4);
if (buttonState3 == LOW)
{
int y1 = now.hour();
int y2 = now.minute();
int y3 = now.second();
digitalWrite(light, LOW);
k3 = 1;
k1 = 0;
k2 = 0;
}
if (k3 == 1)
{
DateTime now = rtc.now();
if (now.hour() == y1 && now.minute() == y2 && now.second() == y3)
{
digitalWrite(light, LOW);
}
if (now.hour() == z1 && now.minute() == z2 && now.second() == z3)
{
digitalWrite(light, HIGH);
}
k3 = 1;
}
}
}
i am facing problem in storing time from RTC to uno board i.e. pin 3