// 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 #include #define BUTTON_PIN 10 // Digital IO pin connected to the button. #define PIXEL_PIN 9 // Digital IO pin connected to the NeoPixels. #define PIXEL_COUNT 110 Metro ledMetro = Metro(100); Metro ledMode = Metro(10); // 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; byte potR = A0; int rval; byte potG = A1; int gval; byte potB = A2; int bval; void setup() { pinMode(BUTTON_PIN, INPUT_PULLUP); strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { // Get current button state. if(ledMode.check() == 1){ boolean newState = digitalRead(BUTTON_PIN); rval = map(analogRead(potR),1023,0,0,255); gval = map(analogRead(potG),1023,0,0,255); bval = map(analogRead(potB),1023,0,0,255 ); // 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); if (newState == LOW) { showType++; if (showType > 1) showType=0; // colorWipe(strip.Color(rval, gval, bval), 0); } } // Set the last button state to the old state. oldState = newState;} startShow(showType); } void startShow(int i) { switch(i){ case 1: colorWipe(strip.Color(rval, gval, bval), 0); // Black/off break; case 0: if(ledMetro.check() == 1) {rainbow(0); 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