upload the sketch. Then open up SERIAL MONITOR under the arduino IDE tools, and watch for the serial print line when u press the button.
One Note: this is for RGB, not RGBW neopixels
Code: Select all
//XRAD'S Frankencode Neopixel Servo Single Button press
//use this to activate a prop or some other cool things
//Include some libraries so you can do things
#include <Adafruit_NeoPixel.h>
#define BUTTON 1 // the pin that the momentary pushbutton is attached to. 3.3v to BUTTON, then back to PIN 1. touch 3.3v to PIN 1 to activate
#define NEOPIXELPIN 4 // data pin OUT to the neopixels
#define NUMPIXELS 20// ? how many do you have
#define DELAYVAL1 80 //Delay to write the Adafruit_NeoPixel color
#define BRIGHTNESS 100// 0 to 255
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NEOPIXELPIN, NEO_GRB + NEO_KHZ800);
// Vegetables
int buttonState = 0; // current state of the button
int lastButtonState = 0;
int pos;
void setup() {
Serial.begin(9600); // initialize serial communication
pinMode(BUTTON, INPUT_PULLDOWN); //So I can use +3.3v to button then to BUTTON pin, built into chip
pinMode(NEOPIXELPIN, OUTPUT);// initialize output
pixels.begin(); // initialize the NeoPixel library.
pixels.show(); //clear pixels
pixels.setBrightness(BRIGHTNESS);
}
void loop() {
// read the pushbutton input pin
buttonState = digitalRead(BUTTON);
//compare the buttonState to its previous state
//this code will run once when button pressed
if (buttonState == HIGH) { // button FIRST press
delay (30); // Delay a little bit to avoid button bounce
if (lastButtonState == 0) {
Serial.println("COLORWIPE");
//neopixels light up in one direction
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(100, 0, 0)); // red
pixels.show(); // send data to neopix
delay(DELAYVAL1);
}
lastButtonState = 1;
}
//this code will run once when button pressed again!
else if (lastButtonState == 1) {
Serial.println("COLORWIPE REVERSE");
//neopixels light up in opposite direction
for (int i = NUMPIXELS; i > -1; i--) { //in reverse!!
pixels.setPixelColor(i, pixels.Color(0, 0, 100)); //blue
pixels.show();
delay(DELAYVAL1);
}
lastButtonState = 0;
}
}
}