#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define PIN2 5
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60,PIN,NEO_GRB+NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(60,PIN,NEO_GRB+NEO_KHZ800);
const int buttonPin = 4;
int buttonState = 0;
void setup() {
// put your setup code here, to run once:
strip.begin();
strip.show();
strip2.begin(); // I added this for strip 2
strip2.show(); // I added this for strip 2
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
colorWipe(strip2.Color(255,0,0),50);
colorWipe(strip2.Color(0,255,0),50);
}
void loop() {
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
colorWipe(strip.Color(255,0,0),0);
colorWipe(strip.Color(0,255,0),0)
}else
colorWipe(strip.Color(0,255,0),0);
colorWipe(strip2.Color(0,255,0),0);
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip2.numPixels(); i++) {
strip2.setPixelColor(i, c); // I changed this to ‘strip 2’
strip2.show(); // I changed this to ‘strip 2’
delay(wait);
}
}
Last edited by adafruit_support_bill on Tue Feb 13, 2018 5:18 pm, edited 1 time in total.
Reason:Please use [code] tags when posting code to the forums.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define PIN2 5
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60,PIN,NEO_GRB+NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(60,PIN,NEO_GRB+NEO_KHZ800);
const int buttonPin = 4;
int buttonState = 0;
void setup() {
// put your setup code here, to run once:
strip.begin();
strip.show();
strip2.begin(); // I added this for strip 2
strip2.show(); // I added this for strip 2
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
colorWipe(strip2.Color(255,0,0),50);
colorWipe(strip2.Color(0,255,0),50);
}
void loop() {
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
colorWipe(strip.Color(255,0,0),0);
colorWipe(strip.Color(0,255,0),0)
}else
colorWipe(strip.Color(0,255,0),0);
colorWipe(strip2.Color(0,255,0),0);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip2.numPixels(); i++) {
strip2.setPixelColor(i, c); // I changed this to ‘strip 2’
strip2.show(); // I changed this to ‘strip 2’
delay(wait);
}
}
Im now getting the error of redefinition of' void look()'
Last edited by adafruit_support_bill on Tue Feb 13, 2018 5:57 pm, edited 1 time in total.
Reason:Please use [code] tags when posting code to the forums.
tags when posting code to the forums. Click on the [code] button and paste your code between the tags.
[quote]Im now getting the error of redefinition of' void look()'[/quote]
You still have 2 loop() functions defined. You can only have one.
[code]void loop() {
colorWipe(strip2.Color(255,0,0),50);
colorWipe(strip2.Color(0,255,0),50);
}
void loop() {
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
colorWipe(strip.Color(255,0,0),0);
colorWipe(strip.Color(0,255,0),0)
}else
colorWipe(strip.Color(0,255,0),0);
colorWipe(strip2.Color(0,255,0),0);
}
You can't put an 'else' in the middle of the 'if' clause. You need to close that with a '}' first.
And your 'else' has no scope. You need to define that with a '{' and a '}' as below.
Do the pictures mean you got it working? I couldn't tell from the pic but the neopixel strip should be powered with 5 volts. If things are still not working, try to change in the code buttonstate == LOW. You sometimes get the opposite result depending on how things get wired up and setting an internal pullup resistor on the pin.