Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define BTN_PIN 3
- #define LED_PIN A3
- #define LED_TYPE WS2812B
- #define LED_COLOR 0x7aff0b
- #define TOTAL_LEDS 105
- #define BRIGHTNESS 40 /* 0 to 255 */
- #define LOWEST_BRIGHTNESS 5 /* 0 to 255 */
- #define CHUNK_SIZE_MS 300000 /* 5 minute chunks (1 sentence per chunk) */
- #define INTERVAL_MS 250
- #define HOUR_MAX_LEN 11 /* Maximum amount of letters an hour can have */
- #define SENTENCE_MAX_LEN 26 /* Maximum amount of letters a sentence can have */
- #define POWERUP_SAFETY_DELAY 3000 /* Avoid to fry the LEDs on startup */
- #define DEBUG_MODE false /* Same as holding down the push button */
- CRGB leds[TOTAL_LEDS];
- /* Clock starts at 9am (o'clock) */
- int HOUR_LETTERS[12][HOUR_MAX_LEN] = {
- {94,87,80,73,66}, /* N I N E */
- {31,24,17,10}, /* T E N */
- {95,86,81,72,67,58}, /* E L E V E N */
- {45,38,31,24,17,10}, /* T W E L V E */
- {90,77,76}, /* O N E */
- {62,49,48}, /* T W O */
- {35,34,21,20,7}, /* T H R E E */
- {92,89,78,75,64,61,50,47,36}, /* F O U R */
- {102,93,88,79,74}, /* F I V E */
- {19,8,5}, /* S I X */
- {51,46,37,32}, /* S E V E N */
- {23,18,9,4} /* E I G H T */
- };
- /* Replaceable numbers is the fastest solution I found for variable hours */
- /* e.g.: 888 = {hours}, 999 = {next hours} */
- int SENTENCE_LETTERS[12][SENTENCE_MAX_LEN] = {
- {109, 888}, /* IT IS {hs} O'CLOCK */
- {53,44,39, 28,27,14,13,0, 888}, /* IT IS FIVE PAST {hs} */
- {53,44,39, 43,40,29,26, 888}, /* IT IS TEN PAST {hs} */
- {53,44,39, 96,85,82,71,68,57,54, 888}, /* IT IS QUARTER PAST {hs} */
- {53,44,39, 70,69,56,55,42,41, 888}, /* IT IS TWENTY PAST {hs} */
- {53,44,39, 70,69,56,55,42,41, 28,27,14,13,0, 888}, /* IT IS TWENTYFIVE PAST {hs} */
- {53,44,39, 98,97,84,83, 888}, /* IT IS half PAST {hs} */
- {30,25,16,11, 70,69,56,55,42,41, 28,27,14,13,0, 999}, /* IT IS TWENTYFIVE TO {next-hs} */
- {30,25,16,11, 70,69,56,55,42,41, 999}, /* IT IS TWENTY TO {next-hs} */
- {30,25,16,11, 96,85,82,71,68,57,54, 999}, /* IT IS QUARTER TO {next-hs} */
- {30,25,16,11, 43,40,29,26, 999}, /* IT IS TEN TO {next-hs} */
- {30,25,16,11, 28,27,14,13,0, 999} /* IT IS FIVE TO {next-hs} */
- };
- int manuallyEnteredChunk = 4; /* Updated with the button */
- int currentSentenceOrder = 42; /* Answer to the ultimate question of life, the universe, and everything */
- int prevHourOrder = 0;
- void setup() {
- delay(POWERUP_SAFETY_DELAY);
- FastLED.addLeds<LED_TYPE, LED_PIN>(leds, TOTAL_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- /* Initialize button pin as a pull-up input. */
- pinMode(BTN_PIN, INPUT_PULLUP);
- }
- void loop() {
- int buttonState = digitalRead(BTN_PIN);
- if (buttonState == LOW || DEBUG_MODE) {
- manuallyEnteredChunk = manuallyEnteredChunk + 1;
- }
- int chunk = floor(millis() / CHUNK_SIZE_MS) + manuallyEnteredChunk;
- int sentenceOrder = chunk % 12;
- /* Avoid to change anything if there was no change in the sentence */
- if (sentenceOrder != currentSentenceOrder) {
- currentSentenceOrder = sentenceOrder;
- int hourChunk = floor(chunk / 12);
- int hourOrder24 = hourChunk % 24; /* 0 to 24 on HOUR_LETTERS */
- cleanDisplay();
- /* Only paint LEDs between 9am and 11pm */
- if (hourOrder24 <= 13) {
- /* Lower the brightness between 9pm and 9am */
- FastLED.setBrightness(hourOrder24 >= 12 ? LOWEST_BRIGHTNESS : BRIGHTNESS);
- for (int i = 0; i < SENTENCE_MAX_LEN; i++) {
- int letter = SENTENCE_LETTERS[sentenceOrder][i];
- if (letter < TOTAL_LEDS) {
- //paintLED(letter); *********************************************************
- } else if (letter == 888) {
- int hourOrder = hourChunk % 12; /* 0 to 12 */
- for (int j = 0; j < HOUR_MAX_LEN; j++) {
- paintLED(HOUR_LETTERS[hourOrder][j]);
- }
- } else if (letter == 999) {
- int nextHourChunk = hourChunk + 1;
- int nextHourOrder = nextHourChunk % 12; /* 0 to 12 */
- for (int j = 0; j < HOUR_MAX_LEN; j++) {
- paintLED(HOUR_LETTERS[nextHourOrder][j]);
- }
- }
- }
- }
- FastLED.show();
- }
- delay(INTERVAL_MS);
- }
- void cleanDisplay() {
- for (int i = 0; i < TOTAL_LEDS; i++) {
- leds[i] = CRGB::Black;
- }
- }
- void paintLED(int i) {
- leds[i].setColorCode(LED_COLOR);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement