Skip to content

Commit

Permalink
Fix flickering issues
Browse files Browse the repository at this point in the history
See thebigpotatoe#30
for further information

Fixes thebigpotatoe#30
  • Loading branch information
LarsMichelsen committed Dec 15, 2019
1 parent d909e75 commit 8da9815
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions Super_Simple_RGB_WiFi_Lamp/LEDs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,36 @@ void ledStringInit() {
}

void handleMode() {
// Adapt the leds to the current mode. Please note the differences between Mode and currentMode.
//
// Mode: Is set by the config or the web interface to tell the lamp that a specific mode should
// be shown. The lamp will then change to that mode slowly (see adjustBrightnessAndSwitchMode())
// currentMode: In case this is set to a mode name, the lamp came to the point where a mode should be
// asked to render it's pattern.
// During startup this is set to "". In this situation the mode should not be rendered, but
// adjustBrightnessAndSwitchMode() should be called to introduce Mode.
// This limitation is important to prevent LED flickering
// See: https://github.com/thebigpotatoe/Super-Simple-RGB-WiFi-Lamp/issues/30
EVERY_N_MILLISECONDS(16) {
// Adapt the leds to the current mode. Please note the differences between Mode and currentMode.
//
// Mode: Is set by the config or the web interface to tell the lamp that a specific mode should
// be shown. The lamp will then change to that mode slowly (see adjustBrightnessAndSwitchMode())
// currentMode: In case this is set to a mode name, the lamp came to the point where a mode should be
// asked to render it's pattern.
// During startup this is set to "". In this situation the mode should not be rendered, but
// adjustBrightnessAndSwitchMode() should be called to introduce Mode.
if (currentMode != "") {
auto modeIter = modes.find(currentMode);
if (modeIter == modes.end()) {
// Should only be reached when a user has configured a mode that does not exist (anymore)
Serial.println("[handleMode] - Mode \"" + currentMode + "\" not found, resetting to default");
Mode = "Colour"; // Automatically jump back to colour
return;
}

if (currentMode != "") {
auto modeIter = modes.find(currentMode);
if (modeIter == modes.end()) {
// Should only be reached when a user has configured a mode that does not exist (anymore)
Serial.println("[handleMode] - Mode \"" + currentMode + "\" not found, resetting to default");
Mode = "Colour"; // Automatically jump back to colour
return;
// If mode is found run its render function
modeIter->second->render();
}

// If mode is found run its render function
modeIter->second->render();
}

// Globally adjust the brightness
adjustBrightnessAndSwitchMode();
// Globally adjust the brightness
adjustBrightnessAndSwitchMode();

// Handle Fast LED
FastLED.show();
// FastLED.delay(1000 / FRAMES_PER_SECOND);
// Handle Fast LED
FastLED.show();
}
}

void adjustBrightnessAndSwitchMode() {
Expand Down

0 comments on commit 8da9815

Please sign in to comment.