complete rework of concept
This commit is contained in:
parent
fb95099bd5
commit
9a7069c43f
@ -42,9 +42,15 @@
|
||||
#define MODE_FADE 0x04
|
||||
#define MODE_SMOOTH 0x05
|
||||
|
||||
int white = 0x01;
|
||||
int levelRed = 0x00;
|
||||
int levelGreen = 0x00;
|
||||
int levelBlue = 0x00;
|
||||
int levelWhite = 0x01;
|
||||
|
||||
int mode = MODE_CONSTANT;
|
||||
boolean strobe = false;
|
||||
int modestep = 0;
|
||||
int animationspeed = 10;
|
||||
long steplength = 0;
|
||||
|
||||
IRrecv irrecv(IR_PIN);
|
||||
decode_results results;
|
||||
@ -53,8 +59,8 @@ simtronyx_RGB_LED strip(LED_RED, LED_GREEN, LED_BLUE);
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
pinMode(LED_WHITE, OUTPUT);
|
||||
analogWrite(LED_WHITE, white);
|
||||
strip.setRGB(0x00, 0x00, 0x00);
|
||||
analogWrite(LED_WHITE, levelWhite);
|
||||
strip.setRGB(levelRed, levelGreen, levelBlue);
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
}
|
||||
|
||||
@ -66,19 +72,59 @@ void loop() {
|
||||
//if (results.value & IR_MASK == IR_FILTER) {
|
||||
Serial.println(results.value);
|
||||
switch (results.value) {
|
||||
case IR_KEY_1: mode = MODE_CONSTANT; strip.animateStop(); strip.setR(0x00); break;
|
||||
case IR_KEY_2: mode = MODE_CONSTANT; strip.animateStop(); strip.setG(0x00); break;
|
||||
case IR_KEY_3: mode = MODE_CONSTANT; strip.animateStop(); strip.setB(0x00); break;
|
||||
case IR_KEY_4: mode = MODE_CONSTANT; strip.animateStop(); strip.setR(0x80); break;
|
||||
case IR_KEY_5: mode = MODE_CONSTANT; strip.animateStop(); strip.setG(0x80); break;
|
||||
case IR_KEY_6: mode = MODE_CONSTANT; strip.animateStop(); strip.setB(0x80); break;
|
||||
case IR_KEY_7: mode = MODE_CONSTANT; strip.animateStop(); strip.setR(0xFF); break;
|
||||
case IR_KEY_8: mode = MODE_CONSTANT; strip.animateStop(); strip.setG(0xFF); break;
|
||||
case IR_KEY_9: mode = MODE_CONSTANT; strip.animateStop(); strip.setB(0xFF); break;
|
||||
case IR_KEY_STROBE:
|
||||
mode = MODE_STROBE;
|
||||
case IR_KEY_1: mode = MODE_CONSTANT; levelRed += 51; if (levelRed > 0xff) { levelRed = 0x00; } break;
|
||||
case IR_KEY_2: mode = MODE_CONSTANT; levelGreen += 51; if (levelGreen > 0xff) { levelGreen = 0x00; } break;
|
||||
case IR_KEY_3: mode = MODE_CONSTANT; levelBlue += 51; if (levelBlue > 0xff) { levelBlue = 0x00; } break;
|
||||
case IR_KEY_4: mode = MODE_CONSTANT; levelRed = levelBlue = levelGreen = levelWhite = 0xff; break;
|
||||
case IR_KEY_5: mode = MODE_CONSTANT; levelWhite += 51; if (levelWhite > 0xff) { levelWhite = 0x00; } break;
|
||||
case IR_KEY_6: mode = MODE_CONSTANT; levelRed = levelBlue = levelGreen = levelWhite = 0x00; break;
|
||||
case IR_KEY_7:
|
||||
mode = MODE_CONSTANT;
|
||||
if (levelRed == levelGreen && levelBlue == 0) {
|
||||
// we have the right color tone, just set brightness
|
||||
levelRed += 51; if (levelRed > 0xff) { levelRed = 0x00; };
|
||||
levelGreen += 51; if (levelGreen > 0xff) { levelGreen = 0x00; };
|
||||
} else {
|
||||
// select color tone
|
||||
levelRed = levelGreen = 51;
|
||||
levelBlue = 0;
|
||||
}
|
||||
break;
|
||||
case IR_KEY_8:
|
||||
mode = MODE_CONSTANT;
|
||||
if (levelGreen == levelBlue && levelRed == 0) {
|
||||
// we have the right color tone, just set brightness
|
||||
levelGreen += 51; if (levelGreen > 0xff) { levelGreen = 0x00; };
|
||||
levelBlue += 51; if (levelBlue > 0xff) { levelBlue = 0x00; };
|
||||
} else {
|
||||
// select color tone
|
||||
levelGreen = levelBlue = 51;
|
||||
levelRed = 0;
|
||||
}
|
||||
break;
|
||||
case IR_KEY_9:
|
||||
mode = MODE_CONSTANT;
|
||||
if (levelBlue == levelRed && levelGreen == 0) {
|
||||
// we have the right color tone, just set brightness
|
||||
levelBlue += 51; if (levelBlue > 0xff) { levelBlue = 0x00; };
|
||||
levelRed += 51; if (levelRed > 0xff) { levelRed = 0x00; };
|
||||
} else {
|
||||
// select color tone
|
||||
levelBlue = levelRed = 51;
|
||||
levelGreen = 0;
|
||||
}
|
||||
break;
|
||||
case IR_KEY_FLASH:
|
||||
strip.animateStop();
|
||||
strip.setRGB(0x00, 0x00, 0x00);
|
||||
mode == MODE_FLASH ? mode = MODE_CONSTANT : mode = MODE_FLASH;
|
||||
modestep = 0;
|
||||
steplength = 0;
|
||||
break;
|
||||
case IR_KEY_STROBE:
|
||||
strip.animateStop();
|
||||
mode == MODE_STROBE ? mode = MODE_CONSTANT : mode = MODE_STROBE;
|
||||
modestep = 0;
|
||||
steplength = 0;
|
||||
break;
|
||||
case IR_KEY_FADE:
|
||||
mode = MODE_FADE;
|
||||
@ -100,18 +146,18 @@ void loop() {
|
||||
strip.animateStart();
|
||||
break;
|
||||
case IR_KEY_DIM:
|
||||
white -= 0x10;
|
||||
if (white < 0x00) {
|
||||
white = 0x00;
|
||||
levelWhite -= 0x10;
|
||||
if (levelWhite < 0x00) {
|
||||
levelWhite = 0x00;
|
||||
}
|
||||
analogWrite(LED_WHITE, white);
|
||||
analogWrite(LED_WHITE, levelWhite);
|
||||
break;
|
||||
case IR_KEY_BRIGHT:
|
||||
white += 0x10;
|
||||
if (white > 0xFF) {
|
||||
white = 0xFF;
|
||||
levelWhite += 0x10;
|
||||
if (levelWhite > 0xFF) {
|
||||
levelWhite = 0xFF;
|
||||
}
|
||||
analogWrite(LED_WHITE, white);
|
||||
analogWrite(LED_WHITE, levelWhite);
|
||||
break;
|
||||
default:
|
||||
Serial.print("proto: ");
|
||||
@ -120,17 +166,49 @@ void loop() {
|
||||
Serial.println(results.value, HEX);
|
||||
break;
|
||||
}
|
||||
if (mode == MODE_CONSTANT) {
|
||||
strip.animateStop();
|
||||
analogWrite(LED_WHITE, levelWhite);
|
||||
strip.setRGB(levelRed, levelGreen, levelBlue);
|
||||
}
|
||||
}
|
||||
}
|
||||
irrecv.resume(); // Receive the next value
|
||||
}
|
||||
if (mode == MODE_STROBE) {
|
||||
strobe = !strobe;
|
||||
if (strobe) {
|
||||
analogWrite(LED_WHITE, white);
|
||||
switch (mode) {
|
||||
case MODE_CONSTANT:
|
||||
// do nothing, it's constant after all...
|
||||
break;
|
||||
case MODE_STROBE:
|
||||
steplength--;
|
||||
if (steplength <= 0) {
|
||||
if (modestep == 1) {
|
||||
modestep = 0;
|
||||
analogWrite(LED_WHITE, levelWhite);
|
||||
strip.setRGB(levelRed, levelGreen, levelBlue);
|
||||
} else {
|
||||
modestep = 1;
|
||||
analogWrite(LED_WHITE, 0x00);
|
||||
strip.setRGB(0x00, 0x00, 0x00);
|
||||
}
|
||||
steplength = animationspeed * 10000L;
|
||||
}
|
||||
break;
|
||||
case MODE_FLASH:
|
||||
steplength--;
|
||||
if (steplength <= 0) {
|
||||
switch (modestep) {
|
||||
case 0: levelRed = 0xff; levelGreen = levelBlue = 0x00; modestep = 1; break;
|
||||
case 1: levelGreen = 0xff; levelBlue = levelRed = 0x00; modestep = 2; break;
|
||||
case 2: levelBlue = 0xff; levelRed = levelGreen = 0x00; modestep = 0; break;
|
||||
}
|
||||
analogWrite(LED_WHITE, levelWhite);
|
||||
strip.setRGB(levelRed, levelGreen, levelBlue);
|
||||
steplength = animationspeed * 10000L;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user