This commit is contained in:
Terra Gilbert 2022-08-24 23:30:54 -04:00
parent 346c52ff0c
commit 939619fb12

View file

@ -15,50 +15,173 @@
nodeMCU: 74880 nodeMCU: 74880
-------------------------------------------------------------------------------------------------------------- */ -------------------------------------------------------------------------------------------------------------- */
// comment below to disable serial in-/output and free some RAM // comment below to disable serial in-/output and free some RAM
#define DEBUG #define DEBUG
// nodeMCU - uncomment to compile this sketch for nodeMCU 1.0 / ESP8266, make sure to select the proper board
// type inside the IDE! This mode is NOT supported and only experimental!
// #define NODEMCU
// useWiFi - enable WiFi support, WPS setup only! If no WPS support is available on a router check settings
// further down, set useWPS to false and enter ssid/password there
// #define USEWIFI
// useNTP - enable NTPClient, requires NODEMCU and USEWIFI. This will also enforce AUTODST.
// Configure a ntp server further down below!
// #define USENTP
// RTC selection - uncomment the one you're using, comment all others and make sure pin assignemts for
// DS1302 are correct in the parameters section further down!
// #define RTC_DS1302
// #define RTC_DS1307
#define RTC_DS3231
// autoDST - uncomment to enable automatic DST switching, check Time Change Rules below!
// #define AUTODST
// FADING - uncomment to enable fading effects for dots/digits, other parameters further down below
// #define FADING
// autoBrightness - uncomment to enable automatic brightness adjustments by using a photoresistor/LDR
// #define AUTOBRIGHTNESS
// customDisplay - uncomment this to enable displayMyStuff(). It's an example of how to display values
// at specified times, like temperature readouts
// #define CUSTOMDISPLAY
// FastForward will speed up things and advance time, this is only for testing purposes!
// Disables AUTODST, USENTP and USERTC.
// #define FASTFORWARD
// customHelper will start some kind of assistant when adapting this sketch to other led layouts, this
// tests all the steps neccessary to run it on almost any led strip configuration.
// #define CUSTOMHELPER
/* ----------------------------------------------------------------------------------------------------- */ /* ----------------------------------------------------------------------------------------------------- */
#include <TimeLib.h> // "Time" by Michael Margolis, used in all configs #include <TimeLib.h> // "Time" by Michael Margolis, used in all configs
#include <EEPROM.h> // required for reading/saving settings to eeprom #include <EEPROM.h> // required for reading/saving settings to eeprom
/* Start RTC config/parameters--------------------------------------------------------------------------
Check pin assignments for DS1302 (SPI), others are I2C (A4/A5 on Arduino by default)
Currently all types are using the "Rtc by Makuna" library */
#ifdef RTC_DS1302
#include <ThreeWire.h>
#include <RtcDS1302.h>
ThreeWire myWire(7, 6, 8); // IO/DAT, SCLK, CE/RST
RtcDS1302<ThreeWire> Rtc(myWire);
#define RTCTYPE "DS1302"
#define USERTC
#endif
#ifdef RTC_DS1307
#include <Wire.h>
#include <RtcDS1307.h>
RtcDS1307<TwoWire> Rtc(Wire);
#define RTCTYPE "DS1307"
#define USERTC
#endif
#ifdef RTC_DS3231
#include <Wire.h>
#include <RtcDS3231.h>
RtcDS3231<TwoWire> Rtc(Wire);
#define RTCTYPE "DS3231"
#define USERTC
#endif
#if !defined ( USERTC )
#pragma message "No RTC selected, check definitions on top of the sketch!"
#endif
/* End RTC config/parameters---------------------------------------------------------------------------- */
/* Start WiFi config/parameters------------------------------------------------------------------------- */ /* Start WiFi config/parameters------------------------------------------------------------------------- */
const char* wifiSSID = "MySpectrumWiFi80-2G"; #ifdef USEWIFI
const char* wifiPWD = "lazydoll672"; const bool useWPS = true; // set to false to disable WPS and use credentials below
const char* wifiSSID = "maWhyFhy";
const char* wifiPWD = "5up3r1337r0xX0r!";
#endif
/* End WiFi config/parameters--------------------------------------------------------------------------- */ /* End WiFi config/parameters--------------------------------------------------------------------------- */
/* Start NTP config/parameters-------------------------------------------------------------------------- /* Start NTP config/parameters--------------------------------------------------------------------------
Using NTP will enforce autoDST, so check autoDST/time zone settings below! */ Using NTP will enforce autoDST, so check autoDST/time zone settings below! */
#define NTPHOST "pool.ntp.org" #ifdef USENTP
/* I recommend using a local ntp service (many routers offer them), don't spam public ones with dozens
of requests a day, get a rtc! ^^ */
//#define NTPHOST "europe.pool.ntp.org"
#define NTPHOST "192.168.2.1"
#ifndef AUTODST
#define AUTODST
#endif
#endif
/* End NTP config/parameters---------------------------------------------------------------------------- */ /* End NTP config/parameters---------------------------------------------------------------------------- */
/* Start autoDST config/parameters ---------------------------------------------------------------------- /* Start autoDST config/parameters ----------------------------------------------------------------------
Comment/uncomment/add TimeChangeRules as needed, only use 2 (tcr1, tcr2), comment out unused ones! Comment/uncomment/add TimeChangeRules as needed, only use 2 (tcr1, tcr2), comment out unused ones!
Enabling/disabling autoDST will require to set time again, clock will be running in UTC time if autoDST Enabling/disabling autoDST will require to set time again, clock will be running in UTC time if autoDST
is enabled, only display times are adjusted (check serial monitor with DEBUG defined!) is enabled, only display times are adjusted (check serial monitor with DEBUG defined!)
This will also add options for setting the date (Year/Month/Day) when setting time on the clock! */ This will also add options for setting the date (Year/Month/Day) when setting time on the clock! */
#ifdef AUTODST
#include <Timezone.h> // "Timezone" by Jack Christensen #include <Timezone.h> // "Timezone" by Jack Christensen
TimeChangeRule *tcr; TimeChangeRule *tcr;
//----------------------------------------------- //-----------------------------------------------
/* US */ /* US */
TimeChangeRule tcr1 = {"tcr1", First, Sun, Nov, 2, -360}; // utc -6h, valid from first sunday of november at 2am // TimeChangeRule tcr1 = {"tcr1", First, Sun, Nov, 2, -360}; // utc -6h, valid from first sunday of november at 2am
TimeChangeRule tcr2 = {"tcr2", Second, Sun, Mar, 2, -300}; // utc -5h, valid from second sunday of march at 2am // TimeChangeRule tcr2 = {"tcr2", Second, Sun, Mar, 2, -300}; // utc -5h, valid from second sunday of march at 2am
//-----------------------------------------------
/* Europe */
TimeChangeRule tcr1 = {"tcr1", Last, Sun, Oct, 3, 60}; // standard/winter time, valid from last sunday of october at 3am, UTC + 1 hour (+60 minutes) (negative value like -300 for utc -5h)
TimeChangeRule tcr2 = {"tcr2", Last, Sun, Mar, 2, 120}; // daylight/summer time, valid from last sunday of march at 2am, UTC + 2 hours (+120 minutes)
//----------------------------------------------- //-----------------------------------------------
Timezone myTimeZone(tcr1, tcr2); Timezone myTimeZone(tcr1, tcr2);
#endif
/* End autoDST config/parameters ----------------------------------------------------------------------- */ /* End autoDST config/parameters ----------------------------------------------------------------------- */
/* Start autoBrightness config/parameters -------------------------------------------------------------- */
uint8_t upperLimitLDR = 180; // everything above this value will cause max brightness (according to current level) to be used (if it's higher than this)
uint8_t lowerLimitLDR = 50; // everything below this value will cause minBrightness to be used
uint8_t minBrightness = 30; // anything below this avgLDR value will be ignored
const bool nightMode = false; // nightmode true -> if minBrightness is used, colorizeOutput() will use a single color for everything, using HSV
const uint8_t nightColor[2] = { 0, 70 }; // hue 0 = red, fixed brightness of 70, https://github.com/FastLED/FastLED/wiki/FastLED-HSV-Colors
float factorLDR = 1.0; // try 0.5 - 2.0, compensation value for avgLDR. Set dbgLDR true & define DEBUG and watch the serial monitor. Looking...
const bool dbgLDR = false; // ...for values roughly in the range of 120-160 (medium room light), 40-80 (low light) and 0 - 20 in the dark
#ifdef NODEMCU
uint8_t pinLDR = 0; // LDR connected to A0 (nodeMCU only offers this one)
#else
uint8_t pinLDR = 1; // LDR connected to A1 (in case somebody flashes this sketch on arduino and already has an ldr connected to A1)
#endif
uint8_t intervalLDR = 75; // read value from LDR every 75ms (most LDRs have a minimum of about 30ms - 50ms)
uint16_t avgLDR = 0; // we will average this value somehow somewhere in readLDR();
uint16_t lastAvgLDR = 0; // last average LDR value we got
/* End autoBrightness config/parameters ---------------------------------------------------------------- */
#define SKETCHNAME "ClockSketch v7.2" #define SKETCHNAME "ClockSketch v7.2"
#define CLOCKNAME "Retro 7 Segment Clock v3 - The Final One(s), 3 LEDs/segment" #define CLOCKNAME "Retro 7 Segment Clock v3 - The Final One(s), 3 LEDs/segment"
/* Start button config/pins----------------------------------------------------------------------------- */ /* Start button config/pins----------------------------------------------------------------------------- */
#ifdef NODEMCU
const uint8_t buttonA = 13; // momentary push button, 1 pin to gnd, 1 pin to d7 / GPIO_13 const uint8_t buttonA = 13; // momentary push button, 1 pin to gnd, 1 pin to d7 / GPIO_13
const uint8_t buttonB = 14; // momentary push button, 1 pin to gnd, 1 pin to d5 / GPIO_14 const uint8_t buttonB = 14; // momentary push button, 1 pin to gnd, 1 pin to d5 / GPIO_14
#else
const uint8_t buttonA = 3; // momentary push button, 1 pin to gnd, 1 pin to d3
const uint8_t buttonB = 4; // momentary push button, 1 pin to gnd, 1 pin to d4
#endif
/* End button config/pins------------------------------------------------------------------------------- */ /* End button config/pins------------------------------------------------------------------------------- */
/* Start basic appearance config------------------------------------------------------------------------ */ /* Start basic appearance config------------------------------------------------------------------------ */
const bool dotsBlinking = true; // true = only light up dots on even seconds, false = always on const bool dotsBlinking = true; // true = only light up dots on even seconds, false = always on
const bool leadingZero = false; // true = enable a leading zero, 9:00 -> 09:00, 1:30 -> 01:30... const bool leadingZero = false; // true = enable a leading zero, 9:00 -> 09:00, 1:30 -> 01:30...
uint8_t displayMode = 1; // 0 = 24h mode, 1 = 12h mode ("1" will also override setting that might be written to EEPROM!) uint8_t displayMode = 0; // 0 = 24h mode, 1 = 12h mode ("1" will also override setting that might be written to EEPROM!)
uint8_t colorMode = 0; // different color modes, setting this to anything else than zero will overwrite values written to eeprom, as above uint8_t colorMode = 0; // different color modes, setting this to anything else than zero will overwrite values written to eeprom, as above
uint16_t colorSpeed = 750; // controls how fast colors change, smaller = faster (interval in ms at which color moves inside colorizeOutput();) uint16_t colorSpeed = 750; // controls how fast colors change, smaller = faster (interval in ms at which color moves inside colorizeOutput();)
const bool colorPreview = true; // true = preview selected palette/colorMode using "8" on all positions for 3 seconds const bool colorPreview = true; // true = preview selected palette/colorMode using "8" on all positions for 3 seconds
@ -66,34 +189,83 @@ const uint8_t colorPreviewDuration = 3; // duration in
const bool reverseColorCycling = false; // true = reverse color movements const bool reverseColorCycling = false; // true = reverse color movements
const uint8_t brightnessLevels[3] {80, 130, 220}; // 0 - 255, brightness Levels (min, med, max) - index (0-2) will be saved to eeprom const uint8_t brightnessLevels[3] {80, 130, 220}; // 0 - 255, brightness Levels (min, med, max) - index (0-2) will be saved to eeprom
uint8_t brightness = brightnessLevels[0]; // default brightness if none saved to eeprom yet / first run uint8_t brightness = brightnessLevels[0]; // default brightness if none saved to eeprom yet / first run
#ifdef FADING
uint8_t fadeDigits = 2; // fade digit segments, 0 = disabled, 1 = only fade out segments turned off, 2 = fade old out and fade new in
uint8_t fadeDots = 2; // fade dots, 0 = disabled, 1 = turn dots off without fading in/out after specidfied time, 2 = fade in and out
uint8_t fadeDelay = 15; // milliseconds between each fading step, 5-25 should work okay-ish
#endif
/* End basic appearance config-------------------------------------------------------------------------- */ /* End basic appearance config-------------------------------------------------------------------------- */
/* End of basic config/parameters section */ /* End of basic config/parameters section */
/* End of feature/parameter section, unless changing advanced things/modifying the sketch there's absolutely nothing to do further down! */ /* End of feature/parameter section, unless changing advanced things/modifying the sketch there's absolutely nothing to do further down! */
/* library, wifi and ntp stuff depending on above config/parameters */ /* library, wifi and ntp stuff depending on above config/parameters */
#ifdef NODEMCU
#if defined ( USENTP ) && !defined ( USEWIFI ) // enforce USEWIFI when USENTP is defined
#define USEWIFI
#pragma warning "USENTP without USEWIFI, enabling WiFi"
#endif
#ifdef USEWIFI
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#endif
#endif
#ifdef USENTP
#include <NTPClient.h> #include <NTPClient.h>
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, NTPHOST); NTPClient timeClient(ntpUDP, NTPHOST, 0, 60000);
#endif
/* end library stuff */ /* end library stuff */
/* setting feature combinations/options */
#if defined ( FASTFORWARD ) || defined ( CUSTOMHELPER )
bool firstLoop = true;
#ifdef USERTC
#undef USERTC
#endif
#ifdef USEWIFI
#undef USEWIFI
#endif
#ifdef USENTP
#undef USENTP
#endif
#ifdef AUTODST
#undef AUTODST
#endif
#endif
/* setting feature combinations/options */
/* Start of FastLED/clock stuff */ /* Start of FastLED/clock stuff */
#define LEDSTUFF #define LEDSTUFF
#ifdef LEDSTUFF
#ifdef NODEMCU
#define FASTLED_ESP8266_RAW_PIN_ORDER // this means we'll be using the raw esp8266 pin order -> GPIO_12, which is d6 on nodeMCU #define FASTLED_ESP8266_RAW_PIN_ORDER // this means we'll be using the raw esp8266 pin order -> GPIO_12, which is d6 on nodeMCU
#define LED_PIN 12 #define LED_PIN 12 // led data in connected to GPIO_12 (d6/nodeMCU)
#else
#define FASTLED_ALLOW_INTERRUPTS 0 // AVR + WS2812 + IRQ = https://github.com/FastLED/FastLED/wiki/Interrupt-problems
#define LED_PIN 6 // led data in connected to d6 (arduino)
#endif
#define LED_PWR_LIMIT 500 // 500mA - Power limit in mA (voltage is set in setup() to 5v) #define LED_PWR_LIMIT 500 // 500mA - Power limit in mA (voltage is set in setup() to 5v)
#define LED_DIGITS 4 // 4 or 6 digits, HH:MM or HH:MM:SS #define LED_DIGITS 4 // 4 or 6 digits, HH:MM or HH:MM:SS
#define LED_COUNT 63 // Total number of leds, 103 on Retro 7 Segment Clock v3 - The Final One(s) - 3 LEDs/segment #define LED_COUNT 103 // Total number of leds, 103 on Retro 7 Segment Clock v3 - The Final One(s) - 3 LEDs/segment
#if ( LED_DIGITS == 6 )
#define LED_COUNT 157 // leds on the 6 digit version
#endif
#include <FastLED.h> #include <FastLED.h>
uint8_t markerHSV[3] = { 0, 127, 20 }; // this color will be used to "flag" leds for coloring later on while updating the leds uint8_t markerHSV[3] = { 0, 127, 20 }; // this color will be used to "flag" leds for coloring later on while updating the leds
CRGB leds[LED_COUNT]; CRGB leds[LED_COUNT];
CRGBPalette16 currentPalette; CRGBPalette16 currentPalette;
#endif
// start clock specific config/parameters // start clock specific config/parameters
@ -155,44 +327,74 @@ const uint8_t digitPositions[4] = { 0, 1, 2, 3 }; // positions o
const uint16_t segGroups[28][2] PROGMEM = { const uint16_t segGroups[28][2] PROGMEM = {
#endif #endif
#if ( LED_DIGITS == 6 )
const uint8_t digitPositions[6] = { 0, 1, 2, 3, 4, 5 }; // positions of HH:MM:SS
const uint16_t segGroups[42][2] PROGMEM = {
#endif
/* segments 0-27, 4 digits x 7 segments */ /* segments 0-27, 4 digits x 7 segments */
/* digit position 0 */ /* digit position 0 */
{ 8, 16}, // top, a { 6, 8 }, // top, a
{24, 1}, // top right, b { 3, 5 }, // top right, b
{10, 18}, // bottom right, c { 20, 22 }, // bottom right, c
{ 3, 26}, // bottom, d { 17, 19 }, // bottom, d
{19, 11}, // bottom left, e { 14, 16 }, // bottom left, e
{ 2, 25}, // top left, f { 9, 11 }, // top left, f
{17, 9}, // center, g { 0, 2 }, // center, g
/* digit position 1 */ /* digit position 1 */
{32, 40}, // top, a { 40, 42 }, // top, a
{48, 33}, // top right, b { 37, 39 }, // top right, b
{42, 50}, // bottom right, c { 32, 34 }, // bottom right, c
{43, 58}, // bottom, d { 29, 31 }, // bottom, d
{59, 51}, // bottom left, e { 26, 28 }, // bottom left, e
{34, 57}, // top left, f { 43, 45 }, // top left, f
{49, 41}, // center, g { 46, 48 }, // center, g
/* digit position 2 */ /* digit position 2 */
{ 4, 12}, // top, a { 60, 62 }, // top, a
{20, 5}, // top right, b { 57, 59 }, // top right, b
{14, 22}, // bottom right, c { 74, 76 }, // bottom right, c
{15, 30}, // bottom, d { 71, 73 }, // bottom, d
{31, 23}, // bottom left, e { 68, 70 }, // bottom left, e
{ 6, 29}, // top left, f { 63, 65 }, // top left, f
{21, 13}, // center, g { 54, 56 }, // center, g
/* digit position 3 */ /* digit position 3 */
{44, 52}, // top, a { 94, 96 }, // top, a
{60, 37}, // top right, b { 91, 93 }, // top right, b
{46, 54}, // bottom right, c { 86, 88 }, // bottom right, c
{39, 62}, // bottom, d { 83, 85 }, // bottom, d
{55, 47}, // bottom left, e { 80, 82 }, // bottom left, e
{38, 61}, // top left, f { 97, 99 }, // top left, f
{53, 45} // center, g { 100, 102 } // center, g
#if ( LED_DIGITS == 6 ) // add two digits, 14 segments, only used if LED_DIGITS is 6...
/* segments 28-41, 6 digits x 7 segments */
/* (bogus on some models which don't support 6 digits) */
/* digit position 4 */
,{ 114, 116 }, // top, a !! do not remove the "," at the start of this line !!
{ 111, 113 }, // top right, b
{ 128, 130 }, // bottom right, c
{ 125, 127 }, // bottom, d
{ 122, 124 }, // bottom left, e
{ 117, 119 }, // top left, f
{ 108, 110 }, // center, g
/* digit position 5 */
{ 148, 150 }, // top, a
{ 145, 147 }, // top right, b
{ 140, 142 }, // bottom right, c
{ 137, 139 }, // bottom, d
{ 134, 136 }, // bottom left, e
{ 151, 153 }, // top left, f
{ 154, 156 } // center, g
#endif // ...end of digits 5+6
}; };
#if ( LED_DIGITS == 4 ) #if ( LED_DIGITS == 4 )
const uint16_t upperDots[2] PROGMEM = {2}; // leds inside the upper dots (right on L7-QBE) const uint16_t upperDots[2] PROGMEM = { 49, 50 }; // leds inside the upper dots (right on L7-QBE)
const uint16_t lowerDots[2] PROGMEM = {2}; // leds inside the lower dots (left on L7-QBE) const uint16_t lowerDots[2] PROGMEM = { 52, 53 }; // leds inside the lower dots (left on L7-QBE)
#endif
#if ( LED_DIGITS == 6 )
const uint16_t upperDots[4] PROGMEM = { 49, 50, 103, 104 }; // all the leds inside the upper dots (bogus values on some models which don't support 6 digits)
const uint16_t lowerDots[4] PROGMEM = { 52, 53, 106, 107 }; // all the leds inside the lower dots (bogus values on some models which don't support 6 digits)
#endif #endif
// Using above arrays it's very easy to "talk" to the segments. Simply use 0-6 for the first 7 segments, add 7 (7-13) for the second one, 14-20 for third.... // Using above arrays it's very easy to "talk" to the segments. Simply use 0-6 for the first 7 segments, add 7 (7-13) for the second one, 14-20 for third....
@ -245,26 +447,60 @@ uint8_t btnRepeatCounter = 0; // keeps track of how often a button press
void setup() { void setup() {
#ifdef DEBUG #ifdef DEBUG
while ( millis() < 300 ) { // safety delay for serial output while ( millis() < 300 ) { // safety delay for serial output
#ifdef NODEMCU
yield(); yield();
#endif
} }
#ifdef NODEMCU
Serial.begin(74880); Serial.println(F("  ")); Serial.begin(74880); Serial.println(F("  "));
#else
Serial.begin(57600); Serial.println(F("  "));
#endif
#ifdef SKETCHNAME #ifdef SKETCHNAME
Serial.print(SKETCHNAME); Serial.println(F(" starting up...")); Serial.print(SKETCHNAME); Serial.println(F(" starting up..."));
#endif #endif
#ifdef CLOCKNAME #ifdef CLOCKNAME
Serial.print("Clock Type: "); Serial.println(CLOCKNAME); Serial.print("Clock Type: "); Serial.println(CLOCKNAME);
#endif #endif
#ifdef RTCTYPE
Serial.print(F("Configured RTC: ")); Serial.println(RTCTYPE);
#endif
#ifdef LEDSTUFF
Serial.print(F("LED power limit: ")); Serial.print(LED_PWR_LIMIT); Serial.println(F(" mA")); Serial.print(F("LED power limit: ")); Serial.print(LED_PWR_LIMIT); Serial.println(F(" mA"));
Serial.print(F("Total LED count: ")); Serial.println(LED_COUNT); Serial.print(F("Total LED count: ")); Serial.println(LED_COUNT);
Serial.print(F("LED digits: ")); Serial.println(LED_DIGITS); Serial.print(F("LED digits: ")); Serial.println(LED_DIGITS);
#endif
#ifdef AUTODST
Serial.println(F("autoDST enabled")); Serial.println(F("autoDST enabled"));
#endif
#ifdef NODEMCU
Serial.println(F("Configured for nodeMCU")); Serial.println(F("Configured for nodeMCU"));
#ifdef USEWIFI
Serial.println(F("WiFi enabled")); Serial.println(F("WiFi enabled"));
#endif
#ifdef USENTP
Serial.print(F("NTP enabled, NTPHOST: ")); Serial.println(NTPHOST); Serial.print(F("NTP enabled, NTPHOST: ")); Serial.println(NTPHOST);
#endif
#else
Serial.println(F("Configured for Arduino"));
#endif
#ifdef FASTFORWARD
Serial.println(F("!! FASTFORWARD defined !!"));
#endif
while ( millis() < 600 ) { // safety delay for serial output while ( millis() < 600 ) { // safety delay for serial output
#ifdef NODEMCU
yield(); yield();
#endif
} }
#endif #endif
#ifdef AUTOBRIGHTNESS
#ifdef DEBUG
Serial.print(F("autoBrightness enabled, LDR using pin: ")); Serial.println(pinLDR);
#endif
pinMode(pinLDR, INPUT);
#endif
pinMode(buttonA, INPUT_PULLUP); pinMode(buttonA, INPUT_PULLUP);
pinMode(buttonB, INPUT_PULLUP); pinMode(buttonB, INPUT_PULLUP);
@ -279,65 +515,130 @@ void setup() {
} }
#endif #endif
#ifdef LEDSTUFF
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, LED_COUNT).setCorrection(TypicalSMD5050).setTemperature(DirectSunlight).setDither(1); FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, LED_COUNT).setCorrection(TypicalSMD5050).setTemperature(DirectSunlight).setDither(1);
FastLED.setMaxPowerInVoltsAndMilliamps(5, LED_PWR_LIMIT); FastLED.setMaxPowerInVoltsAndMilliamps(5, LED_PWR_LIMIT);
FastLED.clear(); FastLED.clear();
FastLED.show(); FastLED.show();
#ifdef CUSTOMHELPER // customHelper() will run in a loop if defined!
while ( 1 > 0 ) {
customHelper();
}
#endif
#ifdef DEBUG
Serial.println(F("setup(): Lighting up some leds...")); Serial.println(F("setup(): Lighting up some leds..."));
#endif
for ( uint8_t i = 0; i < LED_DIGITS; i++ ) { for ( uint8_t i = 0; i < LED_DIGITS; i++ ) {
showSegment(6, i); showSegment(6, i);
} }
FastLED.show(); FastLED.show();
#endif
#ifdef NODEMCU // if building for nodeMCU...
#ifdef USEWIFI // ...and if using WiFi.....
#ifdef DEBUG
Serial.println(F("Starting up WiFi...")); Serial.println(F("Starting up WiFi..."));
#endif
WiFi.mode(WIFI_STA); // set WiFi mode to STA... WiFi.mode(WIFI_STA); // set WiFi mode to STA...
if ( useWPS ) {
WiFi.begin(WiFi.SSID().c_str(),WiFi.psk().c_str()); // ...and start connecting using saved credentials...
#ifdef DEBUG
Serial.println(F("Using WPS setup / saved credentials"));
#endif
} else {
WiFi.begin(wifiSSID, wifiPWD); // ...or credentials defined in the USEWIFI config section WiFi.begin(wifiSSID, wifiPWD); // ...or credentials defined in the USEWIFI config section
#ifdef DEBUG
Serial.println(F("Using credentials from sketch")); Serial.println(F("Using credentials from sketch"));
#endif
} }
unsigned long startTimer = millis(); unsigned long startTimer = millis();
uint8_t wlStatus = 0; uint8_t wlStatus = 0;
uint8_t counter = 6; uint8_t counter = 6;
#ifdef DEBUG
Serial.print(F("Waiting for WiFi connection... ")); Serial.print(F("Waiting for WiFi connection... "));
#endif
while ( wlStatus == 0 ) { while ( wlStatus == 0 ) {
if ( WiFi.status() != WL_CONNECTED ) wlStatus = 0; else wlStatus = 1; if ( WiFi.status() != WL_CONNECTED ) wlStatus = 0; else wlStatus = 1;
#ifdef LEDSTUFF
if ( millis() - startTimer >= 1000 ) { if ( millis() - startTimer >= 1000 ) {
FastLED.clear(); FastLED.clear();
showDigit(counter, digitPositions[3]); showDigit(counter, digitPositions[3]);
FastLED.show(); FastLED.show();
if ( counter > 0 ) counter--; else wlStatus = 2; if ( counter > 0 ) counter--; else wlStatus = 2;
startTimer = millis(); startTimer = millis();
#ifdef DEBUG
Serial.print(F(".")); Serial.print(F("."));
#endif
} }
#endif
#ifdef NODEMCU
yield(); yield();
#endif
} }
if ( WiFi.status() == WL_CONNECTED ) { // if status is connected... // ...and USENTP defined... if ( WiFi.status() == WL_CONNECTED ) { // if status is connected...
#ifdef USENTP // ...and USENTP defined...
timeClient.begin(); // ...start timeClient timeClient.begin(); // ...start timeClient
#endif
} }
#ifdef DEBUG
Serial.println(); Serial.println();
if ( WiFi.status() != 0 ) { if ( WiFi.status() != 0 ) {
Serial.print(F("setup(): Connected to SSID: ")); Serial.println(WiFi.SSID()); Serial.print(F("setup(): Connected to SSID: ")); Serial.println(WiFi.SSID());
} else Serial.println(F("setup(): WiFi connection failed.")); } else Serial.println(F("setup(): WiFi connection failed."));
#endif
#endif
EEPROM.begin(512);
#endif
#ifdef USERTC
Rtc.Begin();
#ifdef DEBUG
Serial.println(F("setup(): RTC.begin(), 2 second safety delay before")); Serial.println(F("setup(): RTC.begin(), 2 second safety delay before"));
Serial.println(F(" doing any read/write actions!")); Serial.println(F(" doing any read/write actions!"));
#endif
unsigned long tmp_time = millis();
while ( millis() - tmp_time < 2000 ) {
#ifdef NODEMCU
yield(); yield();
#endif
} }
#ifdef DEBUG
Serial.println(F("setup(): RTC initialized"));
#endif
#else
#ifdef DEBUG
Serial.println(F("setup(): No RTC defined!"));
#endif
#endif
#ifdef LEDSTUFF
FastLED.clear(); FastLED.clear();
FastLED.show(); FastLED.show();
/* eeprom settings */
#ifdef nodeMCU
EEPROM.begin(512);
#endif
paletteSwitcher(); paletteSwitcher();
brightnessSwitcher(); brightnessSwitcher();
colorModeSwitcher(); colorModeSwitcher();
displayModeSwitcher(); displayModeSwitcher();
#endif
#ifdef FASTFORWARD
setTime(21, 59, 50, 30, 6, 2021); // h, m, s, d, m, y to set the clock to when using FASTFORWARD
#endif
#ifdef USENTP
syncHelper(); syncHelper();
#endif
clockStatus = 0; // change from 1 (startup) to 0 (running mode) clockStatus = 0; // change from 1 (startup) to 0 (running mode)
#ifdef DEBUG
printTime(); printTime();
Serial.println(F("setup() done")); Serial.println(F("setup() done"));
Serial.println(F("------------------------------------------------------")); Serial.println(F("------------------------------------------------------"));
#endif
} }
@ -806,8 +1107,7 @@ void setupClock() {
setupTime.Day = d; setupTime.Day = d;
#ifdef USERTC #ifdef USERTC
writeTime = { 2000 + y, setupTime.Month, setupTime.Day, writeTime = { 2000 + y, setupTime.Month, setupTime.Day,
setupTime.Hour, setupTime.Minute, setupTime.Second setupTime.Hour, setupTime.Minute, setupTime.Second };
};
Rtc.SetDateTime(writeTime); Rtc.SetDateTime(writeTime);
setTime(makeTime(setupTime)); setTime(makeTime(setupTime));
#ifdef DEBUG #ifdef DEBUG
@ -887,13 +1187,11 @@ void setupClock() {
#endif #endif
#ifdef USERTC #ifdef USERTC
writeTime = { 1970 + setupTime.Year, setupTime.Month, setupTime.Day, writeTime = { 1970 + setupTime.Year, setupTime.Month, setupTime.Day,
setupTime.Hour, setupTime.Minute, setupTime.Second setupTime.Hour, setupTime.Minute, setupTime.Second };
};
#ifdef AUTODST #ifdef AUTODST
time_t t = myTimeZone.toUTC(makeTime(setupTime)); // get UTC time from entered time time_t t = myTimeZone.toUTC(makeTime(setupTime)); // get UTC time from entered time
writeTime = { 1970 + setupTime.Year, month(t), day(t), writeTime = { 1970 + setupTime.Year, month(t), day(t),
hour(t), minute(t), second(t) hour(t), minute(t), second(t) };
};
#endif #endif
Rtc.SetDateTime(writeTime); Rtc.SetDateTime(writeTime);
setTime(makeTime(setupTime)); setTime(makeTime(setupTime));
@ -1676,8 +1974,7 @@ void syncHelper() {
} }
#ifdef USERTC #ifdef USERTC
ntpTimeConverted = { year(ntpTime), month(ntpTime), day(ntpTime), ntpTimeConverted = { year(ntpTime), month(ntpTime), day(ntpTime),
hour(ntpTime), minute(ntpTime), second(ntpTime) hour(ntpTime), minute(ntpTime), second(ntpTime) };
};
RtcDateTime rtcTime = Rtc.GetDateTime(); // get current time from the rtc.... RtcDateTime rtcTime = Rtc.GetDateTime(); // get current time from the rtc....
#ifdef DEBUG #ifdef DEBUG
if ( ntpTime > 100 ) { if ( ntpTime > 100 ) {