Skip to content

Instantly share code, notes, and snippets.

@mzero
Last active July 26, 2020 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzero/67f58e71a63e34a6515755de82910f98 to your computer and use it in GitHub Desktop.
Save mzero/67f58e71a63e34a6515755de82910f98 to your computer and use it in GitHub Desktop.
#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