I changed the “rainbow” example sketch deejeerie posted to–I hope–be a little more beginner friendly. Adafruit is great because they provide libraries and a lot of example code, but they could stand to have more explanation and best-practices in their example sketches.
I like to have my named variables at the top of my program as much as possible, so that if I decide I want to change a value, I only have to change it in one place. That’s why stuff like the number of NeoPixels (NUMPIXELS), the NeoPixel brightness (BRIGHTNESS), and data pin (PIN) are all at the top. If I decided to add a 144NeoPixel strip to my 60 NeoPixel ring and Jewel, all I would have to do is change one number, NUMPIXELS, from 67 to 211. Same with the brightness of all the NeoPixels. If I am walking around a Con during the day, I might set BRIGHTNESS to 200. But if I’m out on Halloween, maybe I take it down to 75. Just change one number, upload the changes to the Uno, and bam, done.
#include <Adafruit_NeoPixel.h>
#define NUMPIXELS 67 //This is the TOTAL number of NeoPixels you have on your strip. A ring + a Jewel = 60 + 7 = 67
#define PIN 13 //This is the Uno pin your data wire is connected to. I use 13 because it's nice and out of the way.
#define BRIGHTNESS 100 //This is how bright the NeoPixels should be. 255 is brightest, 0 is off.
#define RAINBOWWAIT 20 //Arduino times are in milliseconds. So a value of 20 means a 20 ms wait every time
//"delay()" is called. A value of 1000 means a wait time of 1 s. The smallest allowable
// value is 1, or 0.001 seconds.
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino 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(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: Avoid connecting on a live circuit...if you must, connect GND first.
void setup() {
strip.begin();
strip.setBrightness(BRIGHTNESS);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
rainbowCycle(RAINBOWWAIT);
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show(); //This takes the bits from the code directly above and "pushes" those colors out to the NeoPixels
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);
}
}
If you copy this code, paste it into your Arduino IDE program, and upload it to your Uno, you should see your NeoPixels blasting out some neat color. Play around with the parameters BRIGHTNESS, RAINBOWWAIT, and NUMPIXELS. What happens when you put different numbers in?
When you say you want code for the movie effects, do you just mean the red clockwise pulsing on the back of the proton packs? And by “rainbow startup,” do you mean you want the pack to quickly go through the rainbow, then “land” on red and do pulses?