Hi,
First, been a long time since I've played with code so please forgive ignorance.. also brand spanking new to Arduino.
I'm in the process of soldering up a bunch of NeoPixel sticks and testing in my breadboard with the standard NeoPixel strandtest. I've figured out how to include multiple NeoPixel objects in an array and cycle the array for the setup and loop.
The problem I'm having is that I don't want to go through each function in the standard strandtest example to replace strip.Color with strip[0]. color everytime strip is referenced.
I figured I create a function that was a collection of the strandtest functions - see function: theCycle() and I just figured I could pass the object to that function and have it defined as strip.
So.. strip[ #] gets handed off to theCycle() as an agrument and relabelled to "strip".
When I verify the code, first error that gets thrown is 'cannot convert Adafruit_NeoPixel' to 'int' for argument '1' to voide theCycle(int)...
So.. I get that the object ain't an integer.. but I just don't know how to pass the object into the function.
Here is the code I'm working with:
#include <Adafruit_NeoPixel.h>
//create object array
Adafruit_NeoPixel strip[2] = {
Adafruit_NeoPixel(8, 12, NEO_GRB + NEO_KHZ800),
Adafruit_NeoPixel(8, 11, NEO_GRB + NEO_KHZ800)};
int STICKS = 2; //global count of NeoPixel sticks in object array
void setup() {
for(int theSticks = 0; theSticks < STICKS-1; theSticks++){ //setup all the NeoPixel sticks in array
strip[theSticks].begin();
strip[theSticks].show(); // Initialize all pixels to 'off'
};
}
void loop() {
for(int theSticks = 0; theSticks < STICKS-1; theSticks++){ //have every NeoPixel stick run the strandtest functions
theCycle(strip[theSticks]);
};
}
void theCycle(int strip){ //this function is the collection of NeoPixel functions to run against the strip
colorWipe(strip.Color(255, 255, 255), 50); // White
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
:)
theaterChase(strip.Color(127, 127, 127), 50); // White
theaterChase(strip.Color(127, 0, 0), 50); // Red
theaterChase(strip.Color( 0, 0, 127), 50); // Blue
rainbow(20);
rainbowCycle(20);
theaterChaseRainbow(50);
}
If it is any help, here is the code that came with the generic strandtest example:
// 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 rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// 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();
delay(wait);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// 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);
}
}
Thanks for any help!
-eko