I'm working on a very simple project. I have 10 buttons and 10 Neopixels. All Neopixels start in the OFF position. When button A is pressed, Neopixel A turns ON. When button A is released, Neopixel A turns OFF.
At the moment, I am testing and troubleshooting with just 2 buttons and 2 Neopixels and an Arduino RedBoard.
I have a 1000uF cap and a 1uF cap attached to the 5V and GND pins connected to the Neopixels. I have a resistor between pin 12 on the RedBoard and the DIN pin and I have resistors on both of the button inputs. The buttons close the circuit when pressed and open it when released.
Here is my code
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIXEL_PIN 12
#define PIXEL_COUNT 2
Adafruit_NeoPixel pixel = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_RGB + NEO_KHZ800);
void setup() {
pinMode(2, INPUT);
digitalWrite(2, HIGH);
pixel.begin();
pixel.show();
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(2) == LOW)
{
digitalWrite(PIXEL_PIN, LOW);
}
else
{
digitalWrite(PIXEL_PIN, HIGH);
}
pixel.setPixelColor(0, pixel.Color(0,100,0));
pixel.setPixelColor(1, pixel.Color(0,0,0));
pixel.show();
}
It works... kinda.
As soon as the code is uploaded to the RedBoard, the RED and GREEN diodes of the first Neopixel "0" immediately turn on.
When I press the button attached to pin 2, the first Neopixel turns green (as it should).
If I rewrite the code to turn OFF the Neopixel in all cases...
pixel.setPixelColor(0, pixel.Color(0,0,0));
pixel.setPixelColor(1, pixel.Color(0,0,0));
pixel.show();
... only the RED diode turns on (brighter now that the GREEN diode is not drawing current).
Now, when I press the button attached to pin 2, the Neopixel turns off.
I can't figure out what I'm doing wrong.
Help??