LED-Clock/ledcontrol.ino
2022-11-10 20:03:13 +01:00

122 lines
3.8 KiB
C++

/*
* Callback to set the led
* like the analog time
* struct
*
*/
void ledRefreshCallback() {
temp = allDotsOn ? backlightColor : black;
strip.ClearTo(temp);
for (int dot = 0; dot < NUM_LEDS; dot++) {
#if NUM_LEDS == 60
//1 dot hour marking
if (MOD(dot, 5) == 0) {
strip.SetPixelColor(dot, hourMarkingColor);
}
#endif
#if NUM_LEDS == 24
//1 dot quarter marking
if (MOD(dot, 6) == 0) {
strip.SetPixelColor(dot, hourMarkingColor);
}
#endif
}
strip.SetPixelColor(0, highnoonColor); //define high noon
#if NUM_LEDS == 60
//3 dots hour
strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 - 1 + hourOffset), NUM_LEDS), hourColor);
strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 + 0 + hourOffset), NUM_LEDS), hourColor);
strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 + 1 + hourOffset), NUM_LEDS), hourColor);
if (singleSecond) {
strip.SetPixelColor(MOD(int(currentSec * NUM_LEDS / 60 + 0), NUM_LEDS), allDotsOn ? secondsColor : backlightColor);
}
#else
strip.SetPixelColor(MOD(int(currentHour * NUM_LEDS / 12 + 0 + hourOffset), NUM_LEDS) , hourColor);
#endif
strip.SetPixelColor(MOD(int(currentMin * NUM_LEDS / 60 + 0), NUM_LEDS), minuteColor);
strip.Show();
}
/*
* Callback to animate
* black running for online but not NTP
* white running for connecting
* green running for AP mode
* red running for boot and unconfigured
*/
void bootAnimCallback() {
strip.ClearTo(black);
int tail = -1;
if (clockwiseRing) {
currentSec++;
if (currentSec >= NUM_LEDS) {
currentSec = 0;
}
}
else {
currentSec--;
tail = 1;
if (currentSec < 0) {
currentSec = NUM_LEDS - 1;
}
}
//ToDo change to no valid time
if (iotWebConf.getState() == iotwebconf::OnLine && !NTPreachable) {
strip.ClearTo(white);
strip.SetPixelColor(MOD((currentSec - 0), NUM_LEDS), black);
strip.SetPixelColor(MOD((currentSec - 1 * tail), NUM_LEDS), black);
strip.SetPixelColor(MOD((currentSec - 2 * tail), NUM_LEDS), black);
}
if (iotWebConf.getState() == iotwebconf::Connecting ) {
strip.SetPixelColor(MOD((currentSec - 0), NUM_LEDS), white);
strip.SetPixelColor(MOD((currentSec - 1 * tail), NUM_LEDS), whiter);
strip.SetPixelColor(MOD((currentSec - 2 * tail), NUM_LEDS), white12);
}
if (iotWebConf.getState() == iotwebconf::ApMode ) {
strip.SetPixelColor(MOD((currentSec - 0), NUM_LEDS), lightgreen);
strip.SetPixelColor(MOD((currentSec - 1 * tail), NUM_LEDS), green);
strip.SetPixelColor(MOD((currentSec - 2 * tail), NUM_LEDS), darkgreen);
}
if (iotWebConf.getState() == iotwebconf::Boot || iotWebConf.getState() == iotwebconf::NotConfigured) {
strip.SetPixelColor(MOD((currentSec - 0), NUM_LEDS), orangered);
strip.SetPixelColor(MOD((currentSec - 1 * tail), NUM_LEDS), red);
strip.SetPixelColor(MOD((currentSec - 2 * tail), NUM_LEDS), darkred);
}
strip.Show();
}
/*
* Callback fo the brigthness
* takes 10 values, get the median
* and set the new value
*/
#ifdef LDR_PIN
void brightnessAdjustmentCallback() {
//Serial.println(ldrValue);
//brigthness begin
ldrValue = ldrValue / 10;
if (ldrValue == 0) {
targetBrightness = MAX_BRIGHTNESS;
}
else {
targetBrightness = int(MINIMAL_BRIGHTNESS + (MAX_BRIGHTNESS - MINIMAL_BRIGHTNESS) / ((ldrValue / LDR_SCALE) + 1) );
}
//Serial.println("Brightness: " + String(strip.GetBrightness()) + "(" + String(ldrValue) + ")");
}
/*
* callback for fading the brigthness smootly
*/
void brightnessFadingCallback() {
int currentBrightness = strip.GetBrightness();
int diff = targetBrightness - currentBrightness;
int rate = rint(diff / 10);
strip.SetBrightness(currentBrightness + rate);
strip.Show();
//Serial.println("Brightness: " + String(currentBrightness) + " diff " + String(rate));
}
#endif