//------------------------------------------------------ // neopixel_strip_sw // // Example of neopixel routine changing based on switch // Setup: // - Wire neoPixel strip on pin 6 // - Wire switch between pin 5 and Gnd //------------------------------------------------------ #include boolean swState; // variable for "state" of switch int swPin = 5; // variable for switch pin number // Parameter 1 = number of pixels in strip // 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 // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip) Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, 6, NEO_GRB + NEO_KHZ800); void setup() { pinMode(swPin, INPUT_PULLUP); // Sets digital pin 5 for input strip.begin(); strip.setBrightness(25); // brightness (0-255) strip.show(); // Initialize all pixels to 'off' } void loop() { swState = digitalRead(swPin); // "read" the state of the switch pin if(swState == LOW){ colorWipe(strip.Color(255, 0, 0), 8); // Red colorWipe(strip.Color(10, 0, 0), 8); // Red } else { colorWipe(strip.Color(0, 0, 255), 20); // Blue colorWipe(strip.Color(0, 0, 10), 20); // Blue } } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i