Last active
April 6, 2020 18:17
-
-
Save oschonrock/2ecc804de215b1e953f9bdd05614e627 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 <Adafruit_NeoPixel.h> | |
#include <DS3231_Simple.h> | |
// Which pin on the Arduino is connected to the NeoPixels? | |
const int LEDCLOCK_PIN = 6; | |
const int LEDDOWNLIGHT_PIN = 5; | |
// How many NeoPixels are attached to the Arduino? | |
const int LEDCLOCK_COUNT = 207; | |
const int LEDDOWNLIGHT_COUNT = 12; | |
// like RGB html hex colour values | |
const uint32_t clockMinuteColour = 0xf67714; | |
const uint32_t clockHourColour = 0x3eb6e9; | |
const uint32_t downlightsColour = 0x8b3ee9; | |
Adafruit_NeoPixel clock(LEDCLOCK_COUNT, LEDCLOCK_PIN); | |
Adafruit_NeoPixel downlights(LEDDOWNLIGHT_COUNT, LEDDOWNLIGHT_PIN); | |
DS3231_Simple RTC; | |
const byte numReadings = 10; | |
int readings[numReadings] {}; | |
byte readIndex = 0; | |
int totalBrightness = 0; | |
void setup() { | |
RTC.begin(); | |
clock.begin(); | |
downlights.begin(); | |
} | |
void loop() { | |
displayTime(); | |
downlights.fill(downlightsColour, 0, LEDDOWNLIGHT_COUNT); | |
setBrightness(); | |
clock.show(); | |
downlights.show(); | |
} | |
void setBrightness() { | |
//get an average light level from previouse set of samples | |
totalBrightness -= readings[readIndex]; | |
readings[readIndex] = analogRead(A0); | |
totalBrightness += readings[readIndex]; | |
if (++readIndex >= numReadings) readIndex = 0; | |
byte brightness = constrain(map(totalBrightness / numReadings, 50, 1023, 255, 30), 1, 255); | |
clock.setBrightness(brightness); | |
downlights.setBrightness(brightness); | |
} | |
void displayTime() { | |
clock.clear(); | |
DateTime Now = RTC.read(); | |
displayDigit(Now.Minute % 10, 0, clockMinuteColour); | |
displayDigit(Now.Minute / 10, 63, clockMinuteColour); | |
byte Hour = Now.Hour; | |
if (Hour > 12) Hour -= 12; | |
displayDigit(Hour % 10, 126, clockHourColour); | |
if (Hour > 9) clock.fill(clockHourColour,189, 18); | |
} | |
void displayDigit(byte digit, int offset, uint32_t colour) { | |
switch (digit) { | |
case 0: | |
clock.fill(colour, (0 + offset), 27); | |
clock.fill(colour, (36 + offset), 27); | |
break; | |
case 1: | |
clock.fill(colour, (0 + offset), 9); | |
clock.fill(colour, (36 + offset), 9); | |
break; | |
case 2: | |
clock.fill(colour, (0 + offset), 18); | |
clock.fill(colour, (27 + offset), 9); | |
clock.fill(colour, (45 + offset), 18); | |
break; | |
case 3: | |
clock.fill(colour, (0 + offset), 18); | |
clock.fill(colour, (27 + offset), 27); | |
break; | |
case 4: | |
clock.fill(colour, (0 + offset), 9); | |
clock.fill(colour, (18 + offset), 27); | |
break; | |
case 5: | |
clock.fill(colour, (9 + offset), 45); | |
break; | |
case 6: | |
clock.fill(colour, (9 + offset), 54); | |
break; | |
case 7: | |
clock.fill(colour, (0 + offset), 18); | |
clock.fill(colour, (36 + offset), 9); | |
break; | |
case 8: | |
clock.fill(colour, (0 + offset), 63); | |
break; | |
case 9: | |
clock.fill(colour, (0 + offset), 54); | |
break; | |
default: | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment