Last active
July 26, 2020 04:44
-
-
Save mzero/67f58e71a63e34a6515755de82910f98 to your computer and use it in GitHub Desktop.
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
#include "RTClib.h" | |
#include <Adafruit_MCP23017.h> | |
#define NUM_ONES_LEDS 4 | |
enum { | |
pinFirst = 0, | |
pinLast = 15, | |
pinJanuary = 0, | |
pinFebruary, | |
pinMarch, | |
pinApril, | |
pinMay, | |
pinJune, | |
pinJuly, | |
pinAugust, | |
pinSeptember, | |
pinOctober, | |
pinNovember, | |
pinDecember | |
}; | |
RTC_DS3231 rtc; | |
Adafruit_MCP23017 mcp3; | |
void setup() { | |
mcp3.begin(B001); | |
for (int pin = pinFirst; pin <= pinLast; ++pin) { | |
mcp3.pinMode(pin, OUTPUT); | |
mcp3.digitalWrite(pin, LOW); | |
} | |
Serial.begin(115200); // might as well make it fast, your computer is! | |
while (!Serial); // this will stall until Sreial is read | |
if (! rtc.begin()) { | |
Serial.println("Couldn't find RTC"); | |
while (1); | |
} | |
if (rtc.lostPower()) { | |
Serial.println("RTC lost power, lets set the time!"); | |
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); | |
} | |
} | |
const char * daysOfTheWeek[7] = | |
{ "Sunday", "Monday", "Tuesday", "Wednesday", | |
"Thursday", "Friday", "Saturday" }; | |
void loop () { | |
DateTime now = rtc.now(); | |
Serial.printf("%d/%d/%d (%s) %2d:%02d:%02d\n", | |
now.year(), now.month(), now.day(), | |
daysOfTheWeek[now.dayOfTheWeek()], | |
now.hour(), now.minute(), now.second() | |
); | |
Serial.printf("Temperature: %d C", | |
rtc.getTemperature() | |
); | |
if (now.hour() == 10) { | |
Serial.println("the hour is 10... writing all HIGH"); | |
for (int pin = pinFirst; pin <= pinLast; ++pin) | |
mcp3.digitalWrite(pin, HIGH); | |
} | |
else { | |
Serial.println("the hour is not yet 10...."); | |
} | |
delay(1000); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment