Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Always start modes with initial settings
Browse files Browse the repository at this point in the history
In previous versions the board kept runtime information per mode
when switching between modes. This could have odd effects, for
example the "color wipe" mode could be invisible for some time
when it was in the "fade out" phase when switching to the mode.
  • Loading branch information
LarsMichelsen committed Dec 15, 2019
1 parent c482d6c commit bc51b33
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 46 deletions.
6 changes: 6 additions & 0 deletions Super_Simple_RGB_WiFi_Lamp/LEDs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ void adjustBrightness() {
// Clear the LEDs
FastLED.clear();

// Initialize state of the new mode
auto modeIter = modes.find(Mode);
if (modeIter != modes.end()) {
modeIter->second->initialize();
}

// Set the currentMode to Mode
currentMode = Mode;
modeChangeFadeAmount = 0;
Expand Down
13 changes: 10 additions & 3 deletions Super_Simple_RGB_WiFi_Lamp/ModeBellCurve.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
class ModeBellCurve : public ModeBase
{
private:
int bellCurveRed = 128;
int bellCurveGreen = 128;
int bellCurveBlue = 128;
int bellCurveRed;
int bellCurveGreen;
int bellCurveBlue;
public:
ModeBellCurve() {}

virtual void initialize() {
int bellCurveRed = 128;
int bellCurveGreen = 128;
int bellCurveBlue = 128;
}

virtual void render() {
// Set the top brightness
for (int i = 0; i < topNumLeds; i++) {
Expand Down
7 changes: 6 additions & 1 deletion Super_Simple_RGB_WiFi_Lamp/ModeCircle.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class ModeCircle : public ModeBase
{
private:
int circleActiveLedNumber = 0;
int circleActiveLedNumber;
public:
ModeCircle() {}

virtual void initialize() {
circleActiveLedNumber = 0;
}

virtual void render() {
// First bring our logical arrays into a list of led numbers to iterate over
int i;
Expand Down
28 changes: 20 additions & 8 deletions Super_Simple_RGB_WiFi_Lamp/ModeClock.ino
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
class ModeClock : public ModeBase
{
private:
int clockHourRed = 128;
int clockHourGreen = 128;
int clockHourBlue = 128;
int clockMinRed = 128;
int clockMinGreen = 128;
int clockMinBlue = 128;
int clockOnPauseBrightness = 255;
unsigned long lastClockExecution = 0;
int clockHourRed;
int clockHourGreen;
int clockHourBlue;
int clockMinRed;
int clockMinGreen;
int clockMinBlue;
int clockOnPauseBrightness;
unsigned long lastClockExecution ;
public:
ModeClock() {}

virtual void initialize() {
clockHourRed = 128;
clockHourGreen = 128;
clockHourBlue = 128;
clockMinRed = 128;
clockMinGreen = 128;
clockMinBlue = 128;
clockOnPauseBrightness = 255;
lastClockExecution = 0;
}

virtual void render() {
if (ntpTimeSet) {
// Get the number of seconds between each LED
Expand Down
22 changes: 16 additions & 6 deletions Super_Simple_RGB_WiFi_Lamp/ModeColorWipe.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
class ModeColorWipe : public ModeBase
{
private:
int colorWipePosition = -1;
bool TurningOn = true;
int colorWipeRed = 255;
int colorWipeGreen = 0;
int colorWipeBlue = 255;
int colorWipeSpeed = 20;
int colorWipePosition;
bool TurningOn;
int colorWipeRed;
int colorWipeGreen;
int colorWipeBlue;
int colorWipeSpeed;

public:
ModeColorWipe() {}

virtual void initialize() {
colorWipePosition = -1;
TurningOn = true;
colorWipeRed = 255;
colorWipeGreen = 0;
colorWipeBlue = 255;
colorWipeSpeed = 20;
}

virtual void render() {
EVERY_N_MILLISECONDS(colorWipeSpeed) {
colorWipePosition++;
Expand Down
13 changes: 10 additions & 3 deletions Super_Simple_RGB_WiFi_Lamp/ModeColour.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
class ModeColour : public ModeBase
{
private:
int colourRed = 128;
int colourGreen = 128;
int colourBlue = 128;
int colourRed;
int colourGreen;
int colourBlue;
public:
ModeColour() {}

virtual void initialize() {
colourRed = 128;
colourGreen = 128;
colourBlue = 128;
}

virtual void render() {
fill_solid(ledString, NUM_LEDS, CRGB(colourRed, colourGreen, colourBlue));
}
Expand Down
13 changes: 10 additions & 3 deletions Super_Simple_RGB_WiFi_Lamp/ModeConfetti.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
class ModeConfetti : public ModeBase
{
private:
bool confettiActive = true;
int confettiSpeed = 100;
int confettiPixel = random(NUM_LEDS);
bool confettiActive;
int confettiSpeed;
int confettiPixel;

public:
ModeConfetti() {}

virtual void initialize() {
confettiActive = true;
confettiSpeed = 100;
confettiPixel = random(NUM_LEDS);
}

virtual void render() {
EVERY_N_MILLISECONDS(confettiSpeed) {
if (confettiActive) {
Expand Down
16 changes: 12 additions & 4 deletions Super_Simple_RGB_WiFi_Lamp/ModeNightRider.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
class ModeNightRider : public ModeBase
{
private:
int nightRiderTopLedNumber = 0;
int nightRiderBottomLedNumber = 0;
int nightRiderTopIncrement = 1;
int nightRiderBottomIncrement = 1;
int nightRiderTopLedNumber;
int nightRiderBottomLedNumber;
int nightRiderTopIncrement;
int nightRiderBottomIncrement;
public:
ModeNightRider() {}

virtual void initialize() {
nightRiderTopLedNumber = 0;
nightRiderBottomLedNumber = 0;
nightRiderTopIncrement = 1;
nightRiderBottomIncrement = 1;
}

virtual void render() {
int delayTime = 500 / topNumLeds;
EVERY_N_MILLISECONDS(delayTime) {
Expand Down
16 changes: 12 additions & 4 deletions Super_Simple_RGB_WiFi_Lamp/ModeRainbow.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
class ModeRainbow : public ModeBase
{
private:
int rainbowStartHue = 0;
int rainbowSpeed = 10;
int rainbowBri = 100;
float rainbowAddedHue = 0;
int rainbowStartHue;
int rainbowSpeed;
int rainbowBri;
float rainbowAddedHue;
public:
ModeRainbow() {}

virtual void initialize() {
rainbowStartHue = 0;
rainbowSpeed = 10;
rainbowBri = 100;
rainbowAddedHue = 0;
}

virtual void render() {
int startHue = rainbowStartHue;
int speed = rainbowSpeed;
Expand Down
22 changes: 16 additions & 6 deletions Super_Simple_RGB_WiFi_Lamp/ModeSparkle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ class ModeSparkle : public ModeBase
{

private:
int sparkleSpeed = 30;
bool sparkleActive = true;
int sparkleRed = 128;
int sparkleGreen = 128;
int sparkleBlue = 128;
int sparklePixel = random(NUM_LEDS);
int sparkleSpeed;
bool sparkleActive;
int sparkleRed;
int sparkleGreen;
int sparkleBlue;
int sparklePixel;
public:
ModeSparkle() {}

virtual void initialize() {
sparkleSpeed = 30;
sparkleActive = true;
sparkleRed = 128;
sparkleGreen = 128;
sparkleBlue = 128;
sparklePixel = random(NUM_LEDS);
}

virtual void render() {
EVERY_N_MILLISECONDS(sparkleSpeed) {
if (sparkleActive) {
Expand Down
28 changes: 20 additions & 8 deletions Super_Simple_RGB_WiFi_Lamp/ModeVisualiser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ private:
arduinoFFT FFT = arduinoFFT();
double visualiserRealSamples[VISUALISER_NUM_SAMPLES];
double visualiserImaginarySamples[VISUALISER_NUM_SAMPLES];
unsigned long visualiserLastSampleTime = 0;
uint16_t visualiserPeriod = 250;
uint16_t visualiserMinThreshold = 100;
uint16_t visualiserMaxThreshold = 750;
uint8_t visualiserNumBinsToSkip = 3;
uint8_t visualiserFadeUp = 32;
uint8_t visualiserFadeDown = 32;
uint8_t visualiserHueOffset = 170;
unsigned long visualiserLastSampleTime;
uint16_t visualiserPeriod;
uint16_t visualiserMinThreshold;
uint16_t visualiserMaxThreshold;
uint8_t visualiserNumBinsToSkip;
uint8_t visualiserFadeUp;
uint8_t visualiserFadeDown;
uint8_t visualiserHueOffset;
public:
ModeVisualiser() {}

virtual void initialize() {
visualiserLastSampleTime = 0;
visualiserPeriod = 250;
visualiserMinThreshold = 100;
visualiserMaxThreshold = 750;
visualiserNumBinsToSkip = 3;
visualiserFadeUp = 32;
visualiserFadeDown = 32;
visualiserHueOffset = 170;
}

virtual void render() {
// Only use visualiser when not trying to access the NTP server
if (((WiFi.isConnected() && ntpTimeSet) || softApStarted) && !webSocketConnecting) {
Expand Down
1 change: 1 addition & 0 deletions Super_Simple_RGB_WiFi_Lamp/Super_Simple_RGB_WiFi_Lamp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ String Password = "";
class ModeBase
{
public:
virtual void initialize();
virtual void render();
virtual void applyConfig(JsonVariant& settings);
};
Expand Down

0 comments on commit bc51b33

Please sign in to comment.