Make brightness changes fade over time.

master
Nekojimi 2 years ago
parent f3a8aa8d59
commit fa19ecf7f7
  1. 46
      project-lamp.ino

@ -56,6 +56,23 @@ struct ColourCode
}
};
enum State
{
COLOUR_DISPLAYED,
SPLIT_DISPLAYED,
FADE_DISPLAYED,
FAN_DISPLAYED,
RUNNING_FAN_DISPLAYED,
STROBE_SELECT_SPEED,
FADE_SELECT_COLOUR,
SPLIT_SELECT_COLOUR,
FAN_SELECT_COLOUR,
};
State state = State.COLOUR_DISPLAYED;
const ColourCode colourCodes[] =
{
{0xE619FF00, 0xFB04EF00, COL_RED},
@ -90,9 +107,16 @@ const int NUM_COLOURCODES = sizeof(colourCodes) / sizeof(ColourCode);
CRGBW leds[NUM_LEDS];
CRGB *ledsRGB = (CRGB *) &leds[0];
CRGBW selectedColours[16];
uint8_t selectedColourCount = 0;
//IRrecv irrecv(IR_RECEIVE_PIN);/
const int BRIGHTNESS_FADE_SPEED = 8;
uint8_t brightness = 128;
uint8_t brightnessTarget = 128;
uint8_t brightnessFade = 0;
uint32_t lastCode = 0;
decode_results results;
@ -185,24 +209,20 @@ void loop()
{
case CODE_BRIGHTER:
brightness += 32;
FastLED.setBrightness(brightness);
FastLED.show();
brightnessTarget = brightness;
Serial.println(F("Brighter"));
break;
case CODE_DIMMER:
brightness -= 32;
FastLED.setBrightness(brightness);
FastLED.show();
brightnessTarget = brightness;
Serial.println(F("Dimmer"));
break;
case CODE_OFF:
FastLED.setBrightness(0);
FastLED.show();
brightnessTarget = 0;
Serial.println(F("Off"));
break;
case CODE_ON:
FastLED.setBrightness(brightness);
FastLED.show();
brightnessTarget = brightness;
Serial.println(F("On"));
break;
default:
@ -213,5 +233,15 @@ void loop()
if (brightness <= 0)
brightness = 255;
}
if (brightnessFade != brightnessTarget)
{
if (brightnessFade < brightnessTarget)
brightnessFade += min(BRIGHTNESS_FADE_SPEED, brightnessTarget - brightnessFade);
else
brightnessFade -= min(BRIGHTNESS_FADE_SPEED, brightnessFade - brightnessTarget);
//brightnessFade = brightnessTarget;
FastLED.setBrightness(brightnessFade);
FastLED.show();
}
delay(100);
}

Loading…
Cancel
Save