I have some neopixels, and I have one hooked up to my teensy. I want to have the color change, when the push button is pressed vs not pressed. The LED will change colour when I upload the code, if I have the button pressed, green, if the button is not pressed, red.
The serial monitor reports changing button press statuses, so I'm not sure why the neopixel isn't changing.
The adafruit website is confusing to me, they have wonderful and involved project examples, but they never have just a basic IO example.
I would appreciate it, if someone could point out where Im going wrong with this code:
#include <Adafruit_NeoPixel.h>
#define PIN 0
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 1
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
const int buttonPin = 2;
int buttonState = 0;
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(0,OUTPUT);
Serial.begin(9600);
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
if (buttonState == LOW) {
pixels.setPixelColor(PIN, pixels.Color(0,33,0)); // green
pixels.show();
}else{
pixels.setPixelColor(PIN, pixels.Color(66,0,0)); // red
pixels.show();
}
delay(500);
}
this code compiles, without errors, and uploads just fine, but pressing the button won't change the LED color.