new effect randomfade, added a few effect parameters and commands
This commit is contained in:
parent
d4b5b41a78
commit
0da6f7a29d
|
@ -17,7 +17,13 @@ uint8_t effect=0;
|
|||
uint8_t movingPoint_x=3;
|
||||
uint8_t movingPoint_y=3;
|
||||
uint8_t wheelPos=0;
|
||||
uint8_t wheelPosSlow=0; //for slower wheelPos increment than 1
|
||||
int wheelSpeed=16; //16=+1/frame
|
||||
int smoothing=80; //0 to 100. 100=no change (ultrasmooth), 0=no smoothing.
|
||||
int strength=50; //how much pixels to apply color to
|
||||
#define EFFECT_SPIRAL 2
|
||||
#define EFFECT_RANDOMFADE 3
|
||||
int fadespeedmax=5; //1 to 255
|
||||
|
||||
|
||||
|
||||
|
@ -137,10 +143,10 @@ uint8_t getAverage(uint8_t array[NUMPIXELS], uint8_t i, int x, int y)
|
|||
void led_smooth()
|
||||
{
|
||||
for (int i=0; i < strip.numPixels(); i++) {
|
||||
uint8_t avgbrightness=pixelR_buffer[i]/3+pixelG_buffer[i]/3+pixelB_buffer[i]/3;
|
||||
pixelR_buffer[i]=0.8*pixelR[i] + 0.2*getAverage(pixelR,i, 0,0);
|
||||
pixelG_buffer[i]=0.8*pixelG[i] + 0.2*getAverage(pixelG,i, 0,0);
|
||||
pixelB_buffer[i]=0.8*pixelB[i] + 0.2*getAverage(pixelB,i, 0,0);
|
||||
//uint8_t avgbrightness=pixelR_buffer[i]/3+pixelG_buffer[i]/3+pixelB_buffer[i]/3;
|
||||
pixelR_buffer[i]=(smoothing/100.0)*pixelR[i] + (1.0-(smoothing/100.0))*getAverage(pixelR,i, 0,0);
|
||||
pixelG_buffer[i]=(smoothing/100.0)*pixelG[i] + (1.0-(smoothing/100.0))*getAverage(pixelG,i, 0,0);
|
||||
pixelB_buffer[i]=(smoothing/100.0)*pixelB[i] + (1.0-(smoothing/100.0))*getAverage(pixelB,i, 0,0);
|
||||
|
||||
}
|
||||
showBuffer();
|
||||
|
@ -149,7 +155,10 @@ void led_smooth()
|
|||
void led_movingPoint()
|
||||
{
|
||||
uint32_t c=wheel(wheelPos);
|
||||
wheelPos=(wheelPos+1)%255;
|
||||
wheelPosSlow+=wheelSpeed;
|
||||
wheelPos=(wheelPos+ (wheelPosSlow/10) )%255;
|
||||
wheelPosSlow=wheelPosSlow%16;
|
||||
|
||||
uint8_t r = (uint8_t)(c >> 16);
|
||||
uint8_t g = (uint8_t)(c >> 8);
|
||||
uint8_t b = (uint8_t)c;
|
||||
|
@ -174,7 +183,7 @@ void led_movingPoint()
|
|||
uint8_t startx=movingPoint_x;
|
||||
uint8_t starty=movingPoint_y;
|
||||
|
||||
for (int i=0;i<50;i++){
|
||||
for (int i=0;i<strength;i++){
|
||||
|
||||
movingPoint_x=startx+8+random(-random(0,2+1),random(0,2+1)+1);
|
||||
movingPoint_y=starty+8+random(-random(0,2+1),random(0,2+1)+1);
|
||||
|
@ -236,11 +245,30 @@ void led_spiral()
|
|||
{
|
||||
wheelPos++;
|
||||
for (int i=0; i < strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i,wheel((wheelPos+i*10)%255));
|
||||
//strip.setPixelColor(i,wheel((wheelPos+i*5)%255));
|
||||
|
||||
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void led_randomfade()
|
||||
{
|
||||
for (int i=0; i < strip.numPixels(); i++) {
|
||||
pixelR_buffer[i]+=random(0,random(0,fadespeedmax+1)+1); //use buffer red channel for color wheel
|
||||
strip.setPixelColor(i,wheel(pixelR_buffer[i]));
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
void set_randomBuffer()
|
||||
{
|
||||
for (int i=0; i < strip.numPixels(); i++) {
|
||||
pixelR_buffer[i]=random(0,256);
|
||||
pixelG_buffer[i]=random(0,256);
|
||||
pixelB_buffer[i]=random(0,256);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t parseColor(String value){
|
||||
|
@ -281,14 +309,33 @@ bool effectHandler(const HomieRange& range, const String& value) {
|
|||
}else if (command.equals("random")){
|
||||
effect=EFFECT_NONE;
|
||||
led_random();
|
||||
}else if (command.equals("set")){
|
||||
}else if (command.equals("set")){ //example: set|37#ff003a
|
||||
effect=EFFECT_NONE;
|
||||
int x=parameters.substring(0,1).toInt();
|
||||
int y=parameters.substring(1,2).toInt();
|
||||
String cstr=parameters.substring(2,9);
|
||||
strip.setPixelColor(xyToPos(x,y), parseColor(cstr));
|
||||
strip.show();
|
||||
}else if (command.equals("smooth")){
|
||||
}else if (command.equals("smooth")){ //example: smooth|[wheelspeed]|[smoothing]|[strength] wheelspeed=1-255, smoothing=0-100, strength=1-255
|
||||
int sepparam = parameters.indexOf("|");
|
||||
int p1=parameters.substring(0,sepparam).toInt();
|
||||
String parameters_part2=parameters.substring(sepparam+1);
|
||||
sepparam = parameters_part2.indexOf("|");
|
||||
int p2=parameters_part2.substring(0,sepparam).toInt();
|
||||
int p3=parameters_part2.substring(sepparam+1).toInt();
|
||||
wheelSpeed=16; //default, speed=+1 /frame
|
||||
if (p1>0){
|
||||
wheelSpeed=p1;
|
||||
}
|
||||
smoothing=80;
|
||||
if (p2>0){
|
||||
smoothing=p2;
|
||||
}
|
||||
strength=50;
|
||||
if (p3>0){
|
||||
strength=p3;
|
||||
}
|
||||
Homie.getLogger() << "-- p1=" << p1 << " p2=" << p2 << " p3=" << p3 << endl;
|
||||
effect=EFFECT_SMOOTH;
|
||||
bufferClear();
|
||||
showBuffer();
|
||||
|
@ -298,6 +345,22 @@ bool effectHandler(const HomieRange& range, const String& value) {
|
|||
bufferClear();
|
||||
showBuffer();
|
||||
strip.show();
|
||||
}else if (command.equals("clearbuffer")){
|
||||
bufferClear();
|
||||
showBuffer();
|
||||
strip.show();
|
||||
}else if (command.equals("randomfade")){ //example: randomfade|5
|
||||
int sepparam = parameters.indexOf("|");
|
||||
int p1=parameters.substring(0,sepparam).toInt();
|
||||
fadespeedmax=5;
|
||||
if (p1>0){
|
||||
fadespeedmax=p1;
|
||||
}
|
||||
effect=EFFECT_RANDOMFADE;
|
||||
set_randomBuffer(); //initialize random
|
||||
}else if (command.equals("randombuffer")){
|
||||
set_randomBuffer(); //set random
|
||||
showBuffer();
|
||||
}
|
||||
|
||||
|
||||
|
@ -368,6 +431,9 @@ void loop() {
|
|||
case EFFECT_SPIRAL:
|
||||
led_spiral();
|
||||
break;
|
||||
case EFFECT_RANDOMFADE:
|
||||
led_randomfade();
|
||||
break;
|
||||
}
|
||||
|
||||
lastMillis=currentMillis;
|
||||
|
|
Loading…
Reference in New Issue