Added breathing mode and adjusted fading speed
This commit is contained in:
parent
587a7ed304
commit
d46229bf4b
1 changed files with 38 additions and 19 deletions
|
@ -49,10 +49,13 @@ unsigned char blueValue;
|
|||
unsigned char decColor;
|
||||
|
||||
// Scale factors
|
||||
float globalScale = 3.0;
|
||||
float redScale = 1.0;
|
||||
float greenScale = 1.0;
|
||||
float blueScale = 0.7;
|
||||
const float globalScale = 3.0;
|
||||
const float redScale = 1.0;
|
||||
const float greenScale = 1.0;
|
||||
const float blueScale = 0.7;
|
||||
float breathScale = 0.999;
|
||||
float breathAdjustment = -0.001;
|
||||
|
||||
|
||||
// HTTP configuration
|
||||
const unsigned char port = 80;
|
||||
|
@ -149,23 +152,30 @@ void loop() {
|
|||
if (red < 0) { red = 0; }
|
||||
if (green < 0) { green = 0; }
|
||||
if (blue < 0) { blue = 0; }
|
||||
if (mode > 1) { mode = 1; }
|
||||
if (mode > 3) { mode = 3; }
|
||||
if (red > 255) { red = 255; }
|
||||
if (green > 255) { green = 255; }
|
||||
if (blue > 255) { blue = 255; }
|
||||
|
||||
// Update values
|
||||
modeValue = mode;
|
||||
if (mode == 1) {
|
||||
|
||||
|
||||
breathScale = 0.999;
|
||||
breathAdjustment = -0.001;
|
||||
decColor = 0;
|
||||
redValue = 255;
|
||||
greenValue = 0;
|
||||
blueValue = 0;
|
||||
} else {
|
||||
|
||||
if (modeValue % 2 == 0) {
|
||||
redValue = red;
|
||||
greenValue = green;
|
||||
blueValue = blue;
|
||||
}
|
||||
if (modeValue % 2 != 0) {
|
||||
redValue = 255;
|
||||
greenValue = 0;
|
||||
blueValue = 0;
|
||||
}
|
||||
|
||||
persistToEEPROM();
|
||||
}
|
||||
} else if (req.indexOf("/get/") != -1) {
|
||||
|
@ -202,9 +212,7 @@ void loop() {
|
|||
}
|
||||
|
||||
void updateLight() {
|
||||
if (modeValue == 0) {
|
||||
// Normal static color mode
|
||||
} else if (modeValue == 1) {
|
||||
if (modeValue % 2 == 1) {
|
||||
// Color cylce mode
|
||||
unsigned short rgbColor[3];
|
||||
rgbColor[0] = redValue;
|
||||
|
@ -224,20 +232,31 @@ void updateLight() {
|
|||
decColor = incColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (modeValue > 1) {
|
||||
// Breath mode
|
||||
breathScale += breathAdjustment;
|
||||
|
||||
if (breathScale <= 0.001 || breathScale >= 0.999) {
|
||||
breathAdjustment = 0 - breathAdjustment;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setLight(redValue, greenValue, blueValue);
|
||||
delay(15);
|
||||
delay(30);
|
||||
}
|
||||
|
||||
/* Helper function to set the colors of the led strip */
|
||||
void setLight(unsigned char red, unsigned char green, unsigned char blue) {
|
||||
analogWrite(redPin, red * globalScale * redScale);
|
||||
analogWrite(greenPin, green * globalScale * greenScale);
|
||||
analogWrite(bluePin, blue * globalScale * blueScale);
|
||||
analogWrite(redPin, red * globalScale * breathScale * redScale);
|
||||
analogWrite(greenPin, green * globalScale * breathScale * greenScale);
|
||||
analogWrite(bluePin, blue * globalScale * breathScale * blueScale);
|
||||
}
|
||||
|
||||
void readFromEEPROM() {
|
||||
unsigned char newMode = EEPROM.read(modeAddress);
|
||||
if (newMode > 1) {
|
||||
if (newMode > 3) {
|
||||
// Uninitialized cells return 255, so reset that
|
||||
modeValue = 0;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue