#include // A basic everyday NeoPixel strip test program. // NEOPIXEL BEST PRACTICES for most reliable operation: // - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections. // - MINIMIZE WIRING LENGTH between microcontroller board and first pixel. // - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR. // - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS // connect GROUND (-) first, then +, then data. // - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip, // a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED. // (Skipping these may work OK on your workbench but can fail in the field) // Which pin on the Arduino is connected to the NeoPixels? // On a Trinket or Gemma we suggest changing this to 1: #define LED_PIN 6 // How many NeoPixels are attached to the Arduino? #define LED_COUNT 10 // Declare our NeoPixel strip object: Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); // Argument 1 = Number of pixels in NeoPixel strip // Argument 2 = Arduino pin number (most are valid) // Argument 3 = Pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) int sw_pin = 2; // Variables will change: int sw_status = 0; // current state of the button int delayval = 500; // delay for half a second // setup() function -- runs once at startup -------------------------------- void setup() { strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) strip.show(); // Turn OFF all pixels ASAP strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) pinMode(sw_pin, INPUT_PULLUP); Serial.begin(9600); } // loop() function -- runs repeatedly as long as board is on --------------- void loop() { sw_status = digitalRead(sw_pin); Serial.println(sw_status); if (sw_status == 0){ strip.clear(); strip.setPixelColor(0, 255, 180, 0); //set the color red on the first pixel strip.show(); //display the color delay(delayval); strip.setPixelColor(1, 0, 255, 50); //set the color green on the first pixel strip.show(); //display the color delay(delayval); strip.setPixelColor(2, 0, 100, 255); //set the color green strip.show(); //display the color delay(delayval); strip.setPixelColor(3, 100, 0, 255); //set the color green strip.show(); //display the color delay(delayval); strip.setPixelColor(4, 255, 180, 0); //set the color red on the first pixel strip.show(); //display the color delay(delayval); strip.setPixelColor(5, 0, 255, 50); //set the color green on the first pixel strip.show(); //display the color delay(delayval); strip.setPixelColor(6, 0, 100, 255); //set the color green strip.show(); //display the color delay(delayval); strip.setPixelColor(7, 100, 0, 255); //set the color green strip.show(); //display the color delay(delayval); strip.setPixelColor(8, 255, 180, 0); //set the color red on the first pixel strip.show(); //display the color delay(delayval); strip.setPixelColor(9, 0, 255, 50); //set the color green on the first pixel strip.show(); //display the color delay(delayval); } else { strip.clear(); strip.show(); } }