Skip to content

Commit

Permalink
Fixed LEDs reminiscence issue when changing num_pixels to a smaller v…
Browse files Browse the repository at this point in the history
…alue - "deactivated" pixels were not controlled anymore and stayed in their previous state.
  • Loading branch information
OnizukaX committed Aug 9, 2018
1 parent 397cb0c commit 05f5065
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions periph_sw/nRF52_RGB_Strip/led_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ class CtrlLED
writeEach(strip.Color(255, 255, 255));
}

// Set all pixels off. Not calling show.
void setPixelsOff(void)
{
for (unsigned int i = 0; i < this->p_settings->num_pixels; ++i)
{
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
}

void switchOff()
{
analogWrite(pinDebug, 0);
Expand Down Expand Up @@ -292,15 +301,6 @@ class CtrlLED
b = map(b, 0, 255, 0, intensity);
return strip.Color(r, g, b);
}

// Set all pixels off. Not calling show.
void setPixelsOff(void)
{
for (unsigned int i = 0; i < this->p_settings->num_pixels; ++i)
{
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
}
};

const CtrlLED::Color CtrlLED::presetColors[CtrlLED::NB_PRESET_COLORS] = {
Expand Down
1 change: 1 addition & 0 deletions periph_sw/nRF52_RGB_Strip/nRF52_RGB_Strip.ino
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ void readUART(uint8_t *const p_ledMode)
break;
case 'A':
Serial.println("[SETTINGS] getting cfg chunk#1 ask for chunk#2");
led.setPixelsOff(); // First switch pixels off to avoid reminiscence.
settings.num_pixels = packetPayload[1];
//Serial.println(String(settings.num_pixels));
settings.device_name = "";
Expand Down

0 comments on commit 05f5065

Please sign in to comment.