Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "RTClib.h"
- RTC_DS1307 rtc;
- const int num_tasks = 6;
- bool timeisup = false; // is the time up ?
- bool failedtasks = false;
- bool active[num_tasks ];
- int switchPins[num_tasks ] = {52, 53, 50, 51, 48, 49}; // list of pins
- int GreenLedPins[num_tasks ] = {22, 24, 26, 28, 30, 32}; // list of pins
- int RedLedPins[num_tasks ] = {23, 25, 27, 29, 31, 33}; // list of pins
- int endHour;
- int endMinute;
- int previousSeconds;
- char comments[num_tasks ][15] = // the number
- {
- "Showering,\t", // change these to possible task names and make fit in "box"
- "Eating,\t",
- "Locking door,\t",
- "Washing,\t",
- "Phone Family,\t",
- "Medication,\t"
- } // list of task names
- void setup() {
- Serial.begin(115200);
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- Serial.flush();
- abort();
- }
- if (! rtc.isrunning()) {
- Serial.println("RTC is NOT running, let's set the time!");
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- }
- DateTime now = rtc.now(); // rtc .now is the reading gives . hour . min .sec
- endHour = now.hour(); // test junk
- endMinute = now.minute() + 1; // test junk
- for ( int x = 0; x < num_tasks ; x++){
- active[x] = false; // sets all tasks to not compteted
- pinMode(switchPins[x] , INPUT_PULLUP); // sets switches pins to input pull up
- pinMode(GreenLedPins[x] , OUTPUT); // sets green leds pins to output
- pinMode(RedLedPins[x ], OUTPUT); // sets red leds pins to output
- digitalWrite(GreenLedPins[x], active[x]); // sets the initial state
- digitalWrite(RedLedPins[x], !active[x]); // sets the initial state
- }
- }
- void loop() {
- DateTime now = rtc.now(); // get the time
- if (!timeisup && endHour == now.hour() && endMinute == now.minute()){
- // check the time isnt up checking for same hour and same min
- Serial.println ( " END OF TIME"); // if same min and hour than time is up is true
- timeisup = true;
- }else{
- if (!timeisup ){
- // print some diag stuff
- diagnostics(now);
- }
- }
- for ( int x = 0; x < num_tasks ; x++){ // creates x and starts at 0 checks all the way trhough to 5
- if (digitalRead(switchPins[x]) == 1){ // switch pins is array of switches
- active[x] = true;
- digitalWrite(GreenLedPins[x], active[x]);
- digitalWrite(RedLedPins[x], !active[x]);
- }
- }
- if ( timeisup ){
- for ( int x = 0; x < num_tasks ; x++){
- if (!active[x]){ // if the task isnt finished
- Serial.print(comments[x]); // print out the failed task name
- Serial.println(active[x]);
- failedtasks = true; // flag for one or more tasks not finished
- }
- }
- if (failedtasks){ // if any failed tasks
- Serial.println(" Failed to complete "); //stick in email code here
- failedtasks = false;
- }else{
- Serial.println(" All tasks completed "); //stick in email code
- }
- delay(5000); // just to see the results
- endHour = now.hour(); // test value
- endMinute = now.minute() + 1; // test value
- // set every thing back to startup values
- reset();
- }
- }
- void diagnostics (DateTime nowthis){
- if (previousSeconds != nowthis.second()){
- Serial.print("End time ");
- Serial.print(endHour , DEC);
- Serial.print(":");
- Serial.print(endMinute, DEC);
- Serial.print(":00");
- Serial.print(" Present time ");
- Serial.print(nowthis.hour(), DEC);
- Serial.print(':');
- Serial.print(nowthis.minute(), DEC);
- Serial.print(':');
- Serial.print(nowthis.second(), DEC);
- Serial.println();
- previousSeconds = nowthis.second();
- }
- }
- void reset(){
- for ( int x = 0; x < num_tasks ; x++){
- active[x] = false; // sets all tasks to not compteted
- digitalWrite(GreenLedPins[x], active[x]); // sets the initial state
- digitalWrite(RedLedPins[x], !active[x]); // sets the initial state
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement