- Thread starter
- #21
Gavinthesheep735
Songster
- Jun 22, 2017
- 75
- 100
- 112
here is a link to the right library - https://goo.gl/A7ER6U
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Door Open
18 hour(s), 36 minute(s)
Light On // here is where the trouble is I would like it to say Door Open Light On.
18 hour(s), 36 minute(s)
Light On
The reason it's not working the way you want is because OnMinLight and OnMinDoor are initialized to different values. So the first pass through the loop it prints "Door Open" (because OnMinDoor = 20) then drops out of the loop and starts over. Then when OnMinLight = 22 it prints "Light On". Try changing OnMinLight =20 and OnMinDoor = 20.
The reason it's not working the way you want is because OnMinLight and OnMinDoor are initialized to different values. So the first pass through the loop it prints "Door Open" (because OnMinDoor = 20) then drops out of the loop and starts over. Then when OnMinLight = 22 it prints "Light On". Try changing OnMinLight =20 and OnMinDoor = 20.
here is a link to the right library - https://goo.gl/A7ER6U
// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
int DoorRelay = 4;
int LightRelay = 5;
const int DoorOpenHour = 6;
const int DoorOpenMinute = 35;
const int DoorCloseHour = 6;
const int DoorCloseMinute = 40;
const int OnHourLight = 6;
const int OnMinLight = 12;
const int OffHourLight = 8;
const int OffMinLight = 28;
void setup () {
Serial.begin(115200);
delay(3000); // wait for console opening
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
// initilize the output and set it's state
pinMode(DoorRelay, OUTPUT);
digitalWrite(DoorRelay, LOW);
}
void loop() {
DateTime now = rtc.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.println(now.minute(), DEC);
if (now.hour() == DoorOpenHour && now.minute() == DoorOpenMinute) {
digitalWrite(DoorRelay, HIGH);
}
if (now.hour() == DoorCloseHour && now.minute() == DoorCloseMinute) {
digitalWrite(DoorRelay, LOW);
}
if (digitalRead(DoorRelay) == HIGH) {
Serial.println("Door Relay On");
}
delay(3000);
}
So what language is that? I understand programming enough to understand what's going on, but it looks too intuitive (i.e., non-cryptic) to be C.