twobuttonstimer/twobuttonstimer.ino

85 lines
1.9 KiB
Arduino
Raw Normal View History

2017-07-26 11:23:09 +00:00
/*
2017-06-18 13:38:59 +00:00
* based on:
2017-07-26 11:23:09 +00:00
* TimeRTC.pde
* example code illustrating Time library with Real Time Clock.
*
*/
2017-06-18 13:38:59 +00:00
#include <TimeLib.h>
2017-07-26 11:23:09 +00:00
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
2017-06-18 13:38:59 +00:00
2017-07-26 11:23:09 +00:00
int led = 13;
int indicator = 0;
2017-06-18 13:38:59 +00:00
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
2017-07-26 11:23:09 +00:00
pinMode(led, OUTPUT);
Serial.begin(9600);
while (!Serial) ; // wait until Arduino Serial Monitor opens
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
2017-06-18 13:38:59 +00:00
}
2017-07-26 11:23:09 +00:00
void loop()
{
2017-06-18 13:38:59 +00:00
if (timeStatus() == timeSet) {
2017-07-26 11:23:09 +00:00
checkTime();
2017-06-18 13:38:59 +00:00
} else {
2017-07-26 11:23:09 +00:00
// fast blinking indicate that time is not set or RTC is not plugged
int i;
for (i = 1; i <= 50; i++)
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(50); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(50); // wait for a second
}
2017-06-18 13:38:59 +00:00
}
2017-07-26 11:23:09 +00:00
delay(1000);
2017-06-18 13:38:59 +00:00
}
void checkTime(){
2017-07-26 11:23:09 +00:00
if ((hour()==6 || hour()==7 ) && (indicator==0)) {
2017-06-18 13:38:59 +00:00
pressSTART();
}
2017-07-26 11:23:09 +00:00
if ((hour()==8) && (minute()==1)) {
2017-06-18 13:38:59 +00:00
pressSTOP();
}
2017-07-26 11:23:09 +00:00
if ((hour()==12 || hour()==13 ) && (indicator==0)) {
2017-06-18 13:38:59 +00:00
pressSTART();
}
2017-07-26 11:23:09 +00:00
if ((hour()==14) && (minute()==1)) {
pressSTOP();
}
if ((hour()==17) && (indicator==0)) {
pressSTART();
}
if ((hour()==18) && (minute()==25)) {
2017-06-18 13:38:59 +00:00
pressSTOP();
}
}
void pressSTOP(){
2017-07-26 11:23:09 +00:00
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
indicator = 0;
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
2017-06-18 13:38:59 +00:00
delay(61000);
}
void pressSTART(){
2017-07-26 11:23:09 +00:00
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
indicator = 1;
digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);
2017-06-18 13:38:59 +00:00
delay(61000);
}