Last active
March 16, 2020 21:02
-
-
Save toast254/915fe8d44495e62fb05e6f3d78e6a5ee to your computer and use it in GitHub Desktop.
Attiny858_washing_machine_peak_hours_start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib | |
// Relay on P1 that trigger washing machine start button | |
// Diagram : https://ae01.alicdn.com/kf/HTB11MlEa2Bj_uVjSZFpq6A0SXXaM.jpg | |
#include <TinyWireM.h> | |
#include "TinyRTClib.h" | |
RTC_DS1307 RTC; | |
void setup () { | |
// RTC | |
TinyWireM.begin(); | |
RTC.begin(); | |
// RELAY | |
pinMode(1, OUTPUT); | |
// set it off | |
digitalWrite(1, HIGH); | |
// // INIT RTC | |
// if (! RTC.isrunning()) { | |
// for (int i = 0; i > 3; i++) { | |
// delay(100); | |
// digitalWrite(1, LOW); | |
// delay(100); | |
// digitalWrite(1, HIGH); | |
// } | |
// // following line sets the RTC to the date & time this sketch was compiled | |
// RTC.adjust(DateTime(__DATE__, __TIME__)); | |
// } | |
} | |
void loop () { | |
// set relay off | |
digitalWrite(1, HIGH); | |
// get curent time | |
DateTime now = RTC.now(); | |
// check if peak hour | |
if (now.hour() == 2 && now.minute() == 35 && now.second() == 0) { | |
// 2h35 | |
digitalWrite(1, LOW); | |
} else if (now.hour() == 12 && now.minute() == 35 && now.second() == 0) { | |
// 12h35 | |
digitalWrite(1, LOW); | |
} | |
// wait some time until next check | |
delay(700); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment