I want to use the neopixel 30 pixel, 1 meter strip with my arduino in my son's playroom under the stairs. I would like to have several color buttons for him to push. Say he pushes the blue button, then the strip will display blue. I would like around 6 or so buttons. (ie, blue, red, yellow, green, orange, rainbow?.., some light show?.., etc.). Not sure if the rainbow and light show are too complex in this project, but it would be cool. I have tried to manipulate the example code given in the downloadable folder, but could not get it to work with multiple button inputs. I only took one C++ class in mechanical engineering school so I am still a beginner at coding. I looked for similar projects or code on google and the adafruit forums but did not see anything similar to what I want to do. Everyone seems to want to use one button and cycle through colors.
Eventually I want to add the audio shield with a speaker so say "blue" when he pushes the blue button and the LED's show blue. This is my wife's idea for him to learn his colors.
Neopixel strip and buttons for children's playroom
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Neopixel strip and buttons for children's playroom
Post a diagram or photo of your circuit so-far and your best attempt at the code and we'll help you figure it out.
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
sketch
- Attachments
-
- Button_sketch.png (143.41 KiB) Viewed 889 times
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
You can see I am way off. I get lost at the boolean. I understand that I dont need the boolean unless I try to have it display the shifting rainbow. But I am now sure how to address specifically for one color. See below.
Code: Select all
// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
// You should wire a momentary push button to connect from ground to a digital IO pin. When you
// press the button it will change to a new pixel animation. Note that you need to press the
// button once to start the first animation!
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN_2 2 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
// Red button
#define BUTTON_PIN_3 3 // Blue button
#define BUTTON_PIN_4 4 // Green button
#define BUTTON_PIN_4 4 // Rainbow
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 30
// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN_2, INPUT_PULLUP);
pinMode(BUTTON_PIN_3, INPUT_PULLUP);
pinMode(BUTTON_PIN_4, INPUT_PULLUP);
pinMode(BUTTON_PIN_5, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN_2);
// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN_2);
if (newState == LOW) {
showType++;
if (showType > 9)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
break;
case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green
break;
case 3: colorWipe(strip.Color(0, 0, 255), 50); // Blue
break;
case 4: theaterChase(strip.Color(127, 127, 127), 50); // White
break;
case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red
break;
case 6: theaterChase(strip.Color( 0, 0, 127), 50); // Blue
break;
case 7: rainbow(20);
break;
case 8: rainbowCycle(20);
break;
case 9: theaterChaseRainbow(50);
break;
}
}
// 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) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
Last edited by adafruit_support_mike on Thu Dec 18, 2014 6:46 pm, edited 1 time in total.
Reason: added CODE tags to preserve formatting
Reason: added CODE tags to preserve formatting
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Neopixel strip and buttons for children's playroom
Debouncing multiple buttons is a bit of a bookkeeping challenge.
You have to keep track of multiple values for each button, so it's easier to put the data in arrays so you can refer to everything by number.
This is the kind of code I use:
It uses a slightly advanced piece of C called an 'enumerated class', but that's really just a way of creating easy-to-read labels in a way the compiler understands.
The 8-bit integers in buttonState[] keep track of the eight most recent readings for each button. That turns the reading-history into numbers, which makes it easy to find specific patterns. The 'switch' statement looks for the patterns that indicate a button has just been pressed, released, or held, and lumps all the other possible patterns togehter as 'IDLE'.
To use the code, call the function at short intervals for every button you want to test:
That looks at each button once every hundredth of a second. Then you can look at the values in buttonState[] to decide how you want to update the pixels.
You have to keep track of multiple values for each button, so it's easier to put the data in arrays so you can refer to everything by number.
This is the kind of code I use:
Code: Select all
uint8_t buttonPin[] = {
BUTTON_PIN_2,
BUTTON_PIN_3,
BUTTON_PIN_4,
BUTTON_PIN_5
};
uint8_t buttonTrace[] = { 0xff, 0xff, 0xff, 0xff };
enum buttonCondition {
JUST_PRESSED, JUST_RELEASED, HELD, IDLE
};
buttonCondition buttonState[] = {
IDLE,
IDLE,
IDLE,
IDLE
};
void checkButton ( uint8_t n ) {
// shift left one bit.. 11111111 becomes 11111110
buttonTrace[ n ] << 1;
// now store a HIGH/LOW reading in the last bit
// 11111110 + (no press) = 11111111
// 11111110 + (press) = 11111110
//
buttonTrace[ n ] += digitalRead( buttonPin[ n ] );
switch ( buttonTrace[ n ] ) {
case 0x80:
// 10000000 - a clean sequence of LOW values after being HIGH
buttonState[ n ] = JUST_PRESSED ; break;
case 0x00:
// 00000000 - button held LOW
buttonState[ n ] = HELD ; break;
case 0x01:
// 00000001 - button went HIGH after being held LOW
buttonState[ n ] = JUST_RELEASED ; break;
default:
buttonState[ n ] = IDLE ; break;
}
}
The 8-bit integers in buttonState[] keep track of the eight most recent readings for each button. That turns the reading-history into numbers, which makes it easy to find specific patterns. The 'switch' statement looks for the patterns that indicate a button has just been pressed, released, or held, and lumps all the other possible patterns togehter as 'IDLE'.
To use the code, call the function at short intervals for every button you want to test:
Code: Select all
void loop () {
for ( int i=0 ; i < 4 ; i++ ) {
checkButton( i );
}
delay( 10 );
}
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
It looks like a I am in over my head on this code. I have played around with this for a few days. I have the code inserted (not sure if it is in the right place) but do not understand it or how to make the next step. I am going to watch some basic you tube videos on C++ so I can get a better understanding on what is going on.
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Neopixel strip and buttons for children's playroom
If you post your code (usingI have the code inserted (not sure if it is in the right place)
Code: Select all
tags or the code button(</>) in the row above your reply window) perhaps we can help.
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
Ok. After some you tube videos I am starting to see what is going on here, but still lacking. Can I get the status of the button and turn on the LEDs from this loop?
Code: Select all
// That looks at each button once every hundredth of a second. Then you can look at the values in buttonState[]
// to decide how you want to update the pixels.
void loop () {
for ( int i=0 ; i < 4 ; i++ )
{
checkButton( i );
//Find out if button 2 has been presses
if (buttonState [BUTTON_PIN_2] == JUST_PRESSED)
{
//Set all pixels to red
colorWipe(strip.Color(255, 0, 0), 50); // Red
}
delay( 10 );
}
}
[list][/list]
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Neopixel strip and buttons for children's playroom
You'd want to put that test after the update loop:
You can also use a loop to check the button states though:
Code: Select all
void loop () {
// First check all the buttons:
for ( int i=0 ; i < 4 ; i++ ) {
checkButton( i );
}
// Then look at the results:
if (buttonState [BUTTON_PIN_2] == JUST_PRESSED) {
//Set all pixels to red
colorWipe(strip.Color(255, 0, 0), 50); // Red
}
delay( 10 );
}
Code: Select all
uint32_t color[] = {
strip.Color( 255, 0, 0 ), // red
strip.Color( 255, 255, 0 ), // yellow
strip.Color( 0, 255, 0 ), // green
strip.Color( 0, 0, 255 ), // blue
};
void loop () {
// First check all the buttons:
for ( int i=0 ; i < 4 ; i++ ) {
checkButton( i );
}
// Then look at the results:
for ( int b=0 ; b < 4 ; b++ ) {
if (buttonState [ b ] == JUST_PRESSED) {
colorWipe( color[ b ] , 50 );
}
}
delay( 10 );
}
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
Ok, this is getting closer. With my current code, the pixel strip will cycle through red, yellow, green and blue with the color wipe funtion. Basically it is cycleing all the colors without any buttons pushed. If the code is correct, i wonder if i need to supply 5 V to the buttons....? Thoughts?
Code: Select all
// This will allow different buttons to display different
// colors on the strip
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN_2 2 // Red button
#define BUTTON_PIN_3 3 // Yellow button
#define BUTTON_PIN_4 4 // Green button
#define BUTTON_PIN_5 5 // Blue button
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 30 // Set number of neopixels on strip
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(BUTTON_PIN_2, INPUT_PULLUP);
pinMode(BUTTON_PIN_3, INPUT_PULLUP);
pinMode(BUTTON_PIN_4, INPUT_PULLUP);
pinMode(BUTTON_PIN_5, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
// The 8-bit integers in buttonState[] keep track of the eight most recent readings for each button.
// That turns the reading-history into numbers, which makes it easy to find specific patterns.
// The 'switch' statement looks for the patterns that indicate a button has just been pressed, released,
// or held, and lumps all the other possible patterns togehter as 'IDLE'.
uint8_t buttonPin[] = {
BUTTON_PIN_2,
BUTTON_PIN_3,
BUTTON_PIN_4,
BUTTON_PIN_5
};
uint8_t buttonTrace[] = { 0xff, 0xff, 0xff, 0xff };
enum buttonCondition {
JUST_PRESSED, JUST_RELEASED, HELD, IDLE
};
buttonCondition buttonState[] = {
IDLE,
IDLE,
IDLE,
IDLE
};
void checkButton ( uint8_t n ) {
// shift left one bit.. 11111111 becomes 11111110
buttonTrace[ n ] << 1;
// now store a HIGH/LOW reading in the last bit
// 11111110 + (no press) = 11111111
// 11111110 + (press) = 11111110
//
buttonTrace[ n ] += digitalRead( buttonPin[ n ] );
switch ( buttonTrace[ n ] ) {
case 0x80:
// 10000000 - a clean sequence of LOW values after being HIGH
buttonState[ n ] = JUST_PRESSED ; break;
case 0x00:
// 00000000 - button held LOW
buttonState[ n ] = HELD ; break;
case 0x01:
// 00000001 - button went HIGH after being held LOW
buttonState[ n ] = JUST_RELEASED ; break;
default:
buttonState[ n ] = IDLE ; break;
}
}
uint32_t color[] = {
strip.Color( 255, 0, 0 ), // red
strip.Color( 255, 255, 0 ), // yellow
strip.Color( 0, 255, 0 ), // green
strip.Color( 0, 0, 255 ), // blue
};
void loop () {
// First check all the buttons:
for ( int i=0 ; i < 4 ; i++ ) {
checkButton( i );
}
delay( 10 );
// Then look at the results:
for ( int b=0 ; b < 4 ; b++ ) {
if (buttonState [ b ] == JUST_PRESSED) {
colorWipe( color[ b ] , 50 );
}
}
}
// 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);
}
}
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Neopixel strip and buttons for children's playroom
You shouldn't need to supply 5v to the buttons. The INPUT_PULLUP pin mode will do that.
Can you post a photo of the actual wiring?
Can you post a photo of the actual wiring?
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
It seems as thou i need normally closed buttons. Here is the wiring pic.
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
The wire leading to pin 4 was not positioned correctly at the switch. I fixed that.
- Barrett_12
- Posts: 9
- Joined: Thu Dec 18, 2014 2:08 am
Re: Neopixel strip and buttons for children's playroom
I started from scratch and finally got this to work. Here is my code. I am sure it could be simplified with arrays, but it works!
Code: Select all
// This program allows for several buttons to trigger specific colors.
// It also allows a button for rainbow and random effects.
#include <Adafruit_NeoPixel.h>
// Define the buttons and pin location
#define BUTTON_PIN_2 2 // Cycle/Random
#define BUTTON_PIN_3 3 // Red
#define BUTTON_PIN_4 4 // Green
#define BUTTON_PIN_5 5 // Blue
#define BUTTON_PIN_6 6 // Yellow
#define BUTTON_PIN_7 7 // Rainbow
#define PIXEL_PIN 10 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 30 // Number of LEDs in the Neopixel
// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
// State variables and initial condition
bool oldState_2 = HIGH;
bool oldState_3 = HIGH;
bool oldState_4 = HIGH;
bool oldState_5 = HIGH;
bool oldState_6 = HIGH;
bool oldState_7 = HIGH;
int showType = 0;
int colorSpeed = 40; // Delay in pixel color wipe
int rainbowSpeed = .8; // Delay in rainbow wipe
int theaterSpeed = 100; // Delay in theater chase
void setup() {
pinMode(BUTTON_PIN_2, INPUT_PULLUP);
pinMode(BUTTON_PIN_3, INPUT_PULLUP);
pinMode(BUTTON_PIN_4, INPUT_PULLUP);
pinMode(BUTTON_PIN_5, INPUT_PULLUP);
pinMode(BUTTON_PIN_6, INPUT_PULLUP);
pinMode(BUTTON_PIN_7, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState_2 = digitalRead(BUTTON_PIN_2);
bool newState_3 = digitalRead(BUTTON_PIN_3);
bool newState_4 = digitalRead(BUTTON_PIN_4);
bool newState_5 = digitalRead(BUTTON_PIN_5);
bool newState_6 = digitalRead(BUTTON_PIN_6);
bool newState_7 = digitalRead(BUTTON_PIN_7);
// Check if button 2 state changed from high to low (button press).
if (newState_2 == LOW && oldState_2 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_2 = digitalRead(BUTTON_PIN_2);
if (newState_2 == LOW) {
showType++;
if (showType > 3)
showType=0;
startShow(showType);}
}
// Check if button 3 state changed from high to low (button press).
else if (newState_3 == LOW && oldState_3 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_3 = digitalRead(BUTTON_PIN_3);
if (newState_3 == LOW) {
colorWipe(strip.Color(255, 0, 0), colorSpeed); // Red
}
}
// Check if button 4 state changed from high to low (button press).
else if (newState_4 == LOW && oldState_4 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_4 = digitalRead(BUTTON_PIN_4);
if (newState_4 == LOW) {
colorWipe(strip.Color(0, 128, 0), colorSpeed); // Green
}
}
// Check if button 5 state changed from high to low (button press).
else if (newState_5 == LOW && oldState_5 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_5 = digitalRead(BUTTON_PIN_5);
if (newState_5 == LOW) {
colorWipe(strip.Color(0, 0, 255), colorSpeed); // Blue
}
}
// Check if button 6 state changed from high to low (button press).
else if (newState_6 == LOW && oldState_6 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_6 = digitalRead(BUTTON_PIN_6);
if (newState_6 == LOW) {
colorWipe(strip.Color(255, 255, 0), colorSpeed); // Yellow
}
}
// Check if button 7 state changed from high to low (button press).
else if (newState_7 == LOW && oldState_7 == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState_7 = digitalRead(BUTTON_PIN_7);
if (newState_7 == LOW) {
rainbowCycle(rainbowSpeed);
}
}
// Set the last button state to the old state.
oldState_2 = newState_2;
oldState_3 = newState_3;
oldState_3 = newState_4;
oldState_3 = newState_5;
oldState_3 = newState_6;
oldState_3 = newState_7;
}
//Cycle
void startShow(int i) {
switch(i){
case 0: theaterChase(strip.Color(127, 127, 127), theaterSpeed); // White
break;
case 1: theaterChase(strip.Color(127, 0, 0), theaterSpeed); // Red
break;
case 2: theaterChase(strip.Color( 0, 0, 127), theaterSpeed); // Blue
break;
case 3: theaterChase(strip.Color( 0, 127, 0), theaterSpeed); // Green
break;
}
}
// 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
}
}
}
}
// 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) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
- Funman1
- Posts: 376
- Joined: Fri Nov 28, 2014 2:13 am
Re: Neopixel strip and buttons for children's playroom
While the arrays may save space and such I would not call them "simplified" :)
Glad you got it working!! :)
Glad you got it working!! :)
Please be positive and constructive with your questions and comments.