Hello,
I was trying to see if anyone had and idea or example for source code with NeoPixels that could simulate the movement of water, or electricity. I am looking to light the LED's in a single color, say blue, and have them animate in such a way that it looks like there are ripples, or electric moving forward through the strip. Once it reaches the end it would start again at the beginning of the strip.
Water/electricity movement pattern with NeoPixels
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- joshuakane
- Posts: 282
- Joined: Sat Apr 13, 2013 4:40 pm
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Water/electricity movement pattern with NeoPixels
There is a "theater chase" pattern in the NeoPixel example sketches. Maybe that would be a good starting place.
- joshuakane
- Posts: 282
- Joined: Sat Apr 13, 2013 4:40 pm
Re: Water/electricity movement pattern with NeoPixels
Thanks, I will check it out!!
- joshuakane
- Posts: 282
- Joined: Sat Apr 13, 2013 4:40 pm
Re: Water/electricity movement pattern with NeoPixels
Hey Rick,
I played with the theater chase, and then ended up going with a pulse using the color wheel, as it had more of a fade, and less of a strobe look to it. I am trying to transition from white to blue to purple and back. I think I am mostly there, but I can't figure out how to tweak the colorwheel code to get the smooth transition I am looking for. Here is what I have so far, any help would be greatly appreciated.
-- Joshua
I played with the theater chase, and then ended up going with a pulse using the color wheel, as it had more of a fade, and less of a strobe look to it. I am trying to transition from white to blue to purple and back. I think I am mostly there, but I can't figure out how to tweak the colorwheel code to get the smooth transition I am looking for. Here is what I have so far, any help would be greatly appreciated.
-- Joshua
Code: Select all
#include <Adafruit_NeoPixel.h>
//Hacked from the original Adafruit library demo
#define PIN 1 //my control pin
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(15, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
//Start out with a purple color
colorWipe(strip.Color(102, 0, 102), 1); // purple
//Throb read and then fade out
PlasmaPulse(30);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void PlasmaPulse(uint8_t wait) {
uint16_t i, j;
//Adjust 60 and 90 to the starting and ending colors you want to fade between.
for(j=128; j<220; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Water/electricity movement pattern with NeoPixels
Not exactly sure what you're looking for. but see what you think of this:
Code: Select all
void PlasmaPulse(uint8_t wait) {
uint16_t i, j;
uint8_t brightness = 255;
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
delay(wait);
//Adjust 60 and 90 to the starting and ending colors you want to fade between.
for(j=170; j>=135; --j) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
brightness -= 6;
strip.setBrightness(brightness);
delay(wait);
}
}
- joshuakane
- Posts: 282
- Joined: Sat Apr 13, 2013 4:40 pm
Re: Water/electricity movement pattern with NeoPixels
Thanks Rick!
One quick question, How can I have the function go ahead and work back up from the dim purple color back to the bright starting color? This would make it perfect!
-- Joshua
One quick question, How can I have the function go ahead and work back up from the dim purple color back to the bright starting color? This would make it perfect!
-- Joshua
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Water/electricity movement pattern with NeoPixels
Like this?
Code: Select all
void PlasmaPulse(uint8_t wait) {
uint16_t i, j;
uint8_t brightness = 255;
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
delay(wait);
//Adjust 60 and 90 to the starting and ending colors you want to fade between.
for(j=170; j>=135; --j) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
brightness -= 6;
strip.setBrightness(brightness);
delay(wait);
}
for(j=135; j<1170; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
brightness += 6;
strip.setBrightness(brightness);
delay(wait);
}
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
delay(wait);
}
- joshuakane
- Posts: 282
- Joined: Sat Apr 13, 2013 4:40 pm
Re: Water/electricity movement pattern with NeoPixels
Thanks again!
This works well.
There was a typo in the code that had a neat result. On the second set you put. for(j=135; j<1170; j++) This resulted in cycling all the colors in the pulse pattern. I really liked that one as well. :-)
This works well.
There was a typo in the code that had a neat result. On the second set you put. for(j=135; j<1170; j++) This resulted in cycling all the colors in the pulse pattern. I really liked that one as well. :-)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Water/electricity movement pattern with NeoPixels
There's nothing like code serendipity! :-)
Please be positive and constructive with your questions and comments.