removed Simtronyx library, first feature complete version

This commit is contained in:
Ronald Schaten 2014-04-25 11:03:41 +02:00
parent 55b602d2c8
commit e26c299b67

View File

@ -1,5 +1,4 @@
#include <IRremote.h>
#include <simtronyx_RGB_LED.h>
#define LED_WHITE 5
#define LED_GREEN 6
@ -50,12 +49,12 @@ int levelTotal = 0x80;
int mode = MODE_CONSTANT;
int modestep = 0;
int modeincrement = 1;
int animationspeed = 5;
long steplength = 0;
IRrecv irrecv(IR_PIN);
decode_results results;
simtronyx_RGB_LED strip(LED_RED, LED_GREEN, LED_BLUE);
void setRGBW(int red, int green, int blue, int white) {
// dim all channels according to levelTotal
@ -63,25 +62,32 @@ void setRGBW(int red, int green, int blue, int white) {
green = map(green, 0x00, 0xff, 0x00, levelTotal);
blue = map(blue, 0x00, 0xff, 0x00, levelTotal);
white = map(white, 0x00, 0xff, 0x00, levelTotal);
// keep output at least at 0x01 if channel is not turned off
if (levelRed > 0) { red = constrain(red, 0x01, 0xff); }
if (levelGreen > 0) { green = constrain(green, 0x01, 0xff); }
if (levelBlue > 0) { blue = constrain(blue, 0x01, 0xff); }
if (levelWhite > 0) { white = constrain(white, 0x01, 0xff); }
if (mode != MODE_STROBE) {
// keep output at least at 0x01 if channel is not turned off
// unless we're in strobe mode, which means that lights should turn off completely
if (levelRed > 0) { red = constrain(red, 0x01, 0xff); }
if (levelGreen > 0) { green = constrain(green, 0x01, 0xff); }
if (levelBlue > 0) { blue = constrain(blue, 0x01, 0xff); }
if (levelWhite > 0) { white = constrain(white, 0x01, 0xff); }
}
// set output
strip.setRGB(red, green, blue);
analogWrite(LED_RED, red);
analogWrite(LED_GREEN, green);
analogWrite(LED_BLUE, blue);
analogWrite(LED_WHITE, white);
}
void setup() {
Serial.begin(9600);
pinMode(LED_RED, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
pinMode(LED_WHITE, OUTPUT);
setRGBW(levelRed, levelGreen, levelBlue, levelWhite);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
strip.loop();
if (irrecv.decode(&results)) {
if (results.decode_type == IR_PROTOCOL) {
if (results.value != 0xFFFFFFFF) {
@ -131,31 +137,21 @@ void loop() {
}
break;
case IR_KEY_FLASH:
strip.animateStop();
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;
strip.animateColorsClear();
strip.animateColorAdd(255, 0, 0, 100);
strip.animateColorAdd( 0, 255, 0, 100);
strip.animateColorAdd( 0, 0, 255, 100);
strip.animateStart();
mode == MODE_FADE ? mode = MODE_CONSTANT : mode = MODE_FADE;
steplength = 0;
break;
case IR_KEY_SMOOTH:
mode == MODE_SMOOTH ? mode = MODE_CONSTANT : mode = MODE_SMOOTH;
strip.animateColorsClear();
strip.animateColorAdd(0x00, 0x00, 0x00, 100);
strip.animateColorAdd(levelRed, levelGreen, levelBlue, 100);
strip.animateStart();
steplength = 0;
modeincrement = 1;
break;
case IR_KEY_DIM: levelTotal = constrain(levelTotal-0x10, 0x01, 0xff); break;
case IR_KEY_BRIGHT: levelTotal = constrain(levelTotal+0x10, 0x01, 0xff); break;
@ -169,7 +165,6 @@ void loop() {
break;
}
if (mode == MODE_CONSTANT) {
strip.animateStop();
setRGBW(levelRed, levelGreen, levelBlue, levelWhite);
}
}
@ -181,6 +176,7 @@ void loop() {
// do nothing, it's constant after all...
break;
case MODE_STROBE:
modestep = constrain(modestep, 0, 1);
steplength--;
if (steplength <= 0) {
if (modestep == 1) {
@ -194,6 +190,7 @@ void loop() {
}
break;
case MODE_FLASH:
modestep = constrain(modestep, 0, 5);
steplength--;
if (steplength <= 0) {
switch (modestep) {
@ -208,7 +205,46 @@ void loop() {
steplength = animationspeed * 10000L;
}
break;
default:
case MODE_FADE:
modestep = constrain(modestep, 0x00, 6 * 0xff);
steplength--;
if (steplength <= 0) {
if (modestep < 1 * 0xff) { // red on, increment green
levelRed = 0xff; levelGreen = modestep % 0xff; levelBlue = 0x00;
} else if (modestep < 2 * 0xff) { // green on, decrement red
levelRed = 0xff - modestep % 0xff; levelGreen = 0xff; levelBlue = 0x00;
} else if (modestep < 3 * 0xff) { // green on, increment blue
levelRed = 0x00; levelGreen = 0xff; levelBlue = modestep % 0xff;
} else if (modestep < 4 * 0xff) { // blue on, decrement green
levelRed = 0x00; levelGreen = 0xff - modestep % 0xff; levelBlue = 0xff;
} else if (modestep < 5 * 0xff) { // blue on, increment red
levelRed = modestep % 0xff; levelGreen = 0x00; levelBlue = 0xff;
} else { // red on, decrement blue
levelRed = 0xff; levelGreen = 0x00; levelBlue = 0xff - modestep % 0xff;
}
setRGBW(levelRed, levelGreen, levelBlue, levelWhite);
steplength = animationspeed * 10000L / 0xff;
modestep++;
if (modestep >= 6 * 0xff) {
modestep = 0;
}
}
break;
case MODE_SMOOTH:
modestep = constrain(modestep, 0x00, 0xff);
steplength--;
if (steplength <= 0) {
int red = map(levelRed, 0x00, 0xff, 0x00, modestep);
int green = map(levelGreen, 0x00, 0xff, 0x00, modestep);
int blue = map(levelBlue, 0x00, 0xff, 0x00, modestep);
int white = map(levelWhite, 0x00, 0xff, 0x00, modestep);
setRGBW(red, green, blue, white);
steplength = animationspeed * 10000L / 0xff;
modestep += modeincrement;
if (modestep <= 0x00 || modestep >= 0xff) {
modeincrement = -modeincrement;
}
}
break;
}
}