Compare commits

..

No commits in common. "09ca988f2b15eeadcafae0e2fd1cc1a8a8d66442" and "a6fac3451ba9df0a16b4166397f4b420060a1666" have entirely different histories.

2 changed files with 14 additions and 25 deletions

View File

@ -1,7 +1,6 @@
#include "SimpLedRGB.h" #include "SimpLedRGB.h"
SimpLedRGB::SimpLedRGB(int pinRed, int pinGreen, int pinBlue) SimpLedRGB::SimpLedRGB(int pinRed, int pinGreen, int pinBlue) {
{
this->pin_red = pinRed; this->pin_red = pinRed;
this->pin_green = pinGreen; this->pin_green = pinGreen;
this->pin_blue = pinBlue; this->pin_blue = pinBlue;
@ -76,32 +75,22 @@ void SimpLedRGB::rainbowCycle(int cycleDurationMillis)
translateToColor(COLOR_RED, cycleDurationMillis); translateToColor(COLOR_RED, cycleDurationMillis);
} }
void SimpLedRGB::candle(const Color &color, float wind) void SimpLedRGB::candle(const Color &color)
{ {
int duration = random(250, 6000 - 5000 * wind); float brightness = (float)random(300, 1000) / 1000.0;
float intensity = (float)random(100 + 400 * wind, 300 + 600 * wind) / 1000.0; int duration = random(100, 1000);
unsigned long start = millis(); translateToColor(
unsigned long finish = start + duration;
float progress = 0.0;
while (progress < 1.0) {
progress = (float)(millis() - start) / (float)duration;
float brightness = (1.0 - intensity) + (1.0 + cos(PI * 2 * progress)) * 0.5 * intensity;
setColor(
{ {
color.red * brightness, color.red * brightness,
color.green * brightness, color.green * brightness,
color.blue * brightness, color.blue * brightness
} },
duration
); );
} }
}
void SimpLedRGB::pulse(const Color &color, float timesPerSecond, float amplitudeMin, float amplitudeMax) void SimpLedRGB::pulse(const Color &color, float timesPerSecond = 1.0, float amplitudeMin = 0.0, float amplitudeMax = 1.0)
{ {
float amplitude = (1.0 + sin(PULSE_PER_SECOND * millis() * timesPerSecond)) / 2.0; float amplitude = (1.0 + sin(PULSE_PER_SECOND * millis() * timesPerSecond)) / 2.0;
float brightness = amplitudeMin + (amplitudeMax - amplitudeMin) * amplitude; float brightness = amplitudeMin + (amplitudeMax - amplitudeMin) * amplitude;

View File

@ -39,7 +39,7 @@ class SimpLedRGB
void rainbowCycle(int cycleDurationMillis); void rainbowCycle(int cycleDurationMillis);
void candle(const Color &color, float wind = 0.5); void candle(const Color &color);
void pulse(const Color &color, float timesPerSecond = 1.0, float amplitudeMin = 0.0, float amplitudeMax = 1.0); void pulse(const Color &color, float timesPerSecond = 1.0, float amplitudeMin = 0.0, float amplitudeMax = 1.0);
}; };