leonvandenbeukel / Round-LED-Clock

Wi-Fi connected round LED Clock
Apache License 2.0
134 stars 64 forks source link

[bug] night time always 0 #12

Open Blaubeermuffin opened 5 years ago

Blaubeermuffin commented 5 years ago

I just tested your script and I'm pretty happy with it. Great work. I just found a small bug though with the night cutoff.

Current code:

boolean night() {

  if (currentDateTime.hour >= NIGHTCUTOFF && currentDateTime.hour <= MORNINGCUTOFF) 
    return true;    
}

This is checking if the current hour bigger than the night cutoff AND smaller than the morning cutoff. What you want to do instead, is to check if the current hour is bigger than the night cutoff OR smaller than the morning cutoff. You could implement it pretty easy with something like this:

boolean night() {
  return ( currentDateTime.hour >= NIGHTCUTOFF ) || ( currentDateTime.hour <= MORNINGCUTOFF );    
}
BlackCatPeanut commented 3 years ago

Just wanted to say thanks to @Blaubeermuffin for the updated code as this has fixed the night light brightness for me.

FransKrau commented 3 years ago

The bug found above, is not the only bug, I think :) When the clock starts in daytime, daytime brightness is oke, Then the clock switches to nightbrightness, at the desired time, but at the morningcutoff time the clock stays (1 hour) in nightbrightness. I think this should be the solution:

add

define DAYBRIGHTNESS 255 // Brightness level from 0 (off) to 255 (full brightness)

change ( currentDateTime.hour <= MORNINGCUTOFF) in ( currentDateTime.hour < MORNINGCUTOFF)

and the 2 last lines of code of this: if ( night() && USE_NIGHTCUTOFF == true ) FastLED.setBrightness (NIGHTBRIGHTNESS); else FastLED.setBrightness (DAYBRIGHTNESS);