#include #define BUTTON_PIN A1 // Digital IO pin connected to the button. This will be // driven with a pull-up resistor so the switch should // pull the pin to ground momentarily. On a high -> low // transition the button press logic will execute. #define PIXEL_PIN 9 // Digital IO pin connected to the NeoPixels. #define PIXEL_COUNT 8 #define BRIGHTNESS 100 // 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, correct if colors are swapped upon testing // NEO_RGBW Pixels are wired for RGBW bistream // 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 = BUTTON_PIN,off; int showType = BUTTON_PIN,on; void setup() { pinMode(BUTTON_PIN, INPUT_PULLUP); strip.setBrightness(BRIGHTNESS); strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { // Get current button state. bool newState = digitalRead(BUTTON_PIN); // Check if state changed from high to low (button press). if (newState == HIGH && oldState == LOW) { // Short delay to debounce button. delay(100); // Check if button is still low after debounce. newState = digitalRead(BUTTON_PIN); if (newState == HIGH) { showType++; if (showType > 4) showType=0; startShow(showType); } } // Set the last button state to the old state. oldState = newState; } void startShow(int on) { switch(on){ case 0: policeLight (); break; case 1: blueStrobe () ; break; case 2: lightAlt (); break; case 3: blueStrobeRed (); break; return; } } void policeLight(){ //SECUENCIA #1 strip.begin(); strip.show(); uint32_t red = strip.Color(255, 255, 0); uint32_t blue = strip.Color(255, 255, 255); uint32_t black = strip.Color(0, 0, 0); for (int i=0; i<12; i++) { int off=4; for (int on=0; on<4; on++) { strip.setPixelColor(on, red); strip.setPixelColor(off, black); off++; strip.show(); } delay(100); off=0; for (int on=4; on<8; on++) { strip.setPixelColor(on, blue); strip.setPixelColor(off, black); off++; strip.show(); } delay(100); off; } } void lightAlt(){ //SECUENCIA #2 strip.begin(); strip.show(); uint32_t red = strip.Color(255, 0, 0); uint32_t blue = strip.Color(0, 0, 255); uint32_t black = strip.Color(0, 0, 0); for (int i=0; i<10; i++) { strip.setPixelColor(0, red); strip.setPixelColor(1, red); strip.setPixelColor(2, black); strip.setPixelColor(3, black); strip.setPixelColor(4, blue); strip.setPixelColor(5, blue); strip.setPixelColor(6, black); strip.setPixelColor(7, black); strip.show(); delay(200); strip.setPixelColor(0, black); strip.setPixelColor(1, black); strip.setPixelColor(2, red); strip.setPixelColor(3, red); strip.setPixelColor(4, black); strip.setPixelColor(5, black); strip.setPixelColor(6, blue); strip.setPixelColor(7, blue); strip.show(); delay(200); } } void blueStrobe(){ //SECUENCIA #3 strip.begin(); strip.show(); uint32_t red = strip.Color(255, 0, 0); uint32_t blue = strip.Color(0, 0, 255); uint32_t white = strip.Color(255, 255, 255); uint32_t black = strip.Color(0, 0, 0); int rep=0; while (rep<4) { int off=0; while (off<8) { strip.setPixelColor(off, black); off++; } strip.show(); off=0; for (int on=0; on<8; on++) { off=on-1; strip.setPixelColor(off, black); strip.setPixelColor(on, blue); strip.show(); delay(50); } for (int on=7; on>-1; on--) { off=on+1; strip.setPixelColor(off, black); strip.setPixelColor(on, red); strip.show(); delay(50); } for (int on=0; on<8; on++) //BLANCO { off=on+1; strip.setPixelColor(off, black); strip.setPixelColor(on, white); strip.show(); delay(50); } for (int on=7; on>-1; on--) { off=on-1; strip.setPixelColor(off, black); strip.setPixelColor(on, white); strip.show(); delay(50); } rep++; BUTTON_PIN,off; //Detener efecto } } void blueStrobeRed(){ //SECUENCIA #4 strip.begin(); strip.show(); uint32_t red = strip.Color(255, 0, 0); uint32_t blue = strip.Color(0, 0, 255); uint32_t white = strip.Color(255, 255, 255); uint32_t black = strip.Color(0, 0, 0); int rep=0; while (rep<4) { int off=0; int on2=7; while (off<8) { strip.setPixelColor(off, black); off++; } strip.show(); off=0; for (int on=0; on<4; on++) { while (off<8) { strip.setPixelColor(off, black); off++; } strip.show(); strip.setPixelColor(on, blue); strip.setPixelColor(on2, blue); strip.show(); on2--; off=0; delay(150); } for (int i=0; i<5; i++) { while (off<8) { strip.setPixelColor(off, black); off++; } strip.show(); } delay(100); strip.setPixelColor(0, white); //BLANCO strip.setPixelColor(2, red); strip.setPixelColor(3, red); strip.setPixelColor(4, red); strip.setPixelColor(5, red); strip.setPixelColor(7, white); //BLANCO strip.setPixelColor(1, white); //BLANCO strip.setPixelColor(6, white); //BLANCO strip.show(); delay(100); strip.setPixelColor(0, black); //BLANCO strip.setPixelColor(7, black); //BLANCO strip.setPixelColor(2, black); strip.setPixelColor(3, black); strip.setPixelColor(4, black); strip.setPixelColor(5, black); strip.setPixelColor(1, black); //BLANCO strip.setPixelColor(6, black); //BLANCO strip.show(); delay(100); strip.setPixelColor(0, white); //BLANCO strip.setPixelColor(7, white); //BLANCO strip.setPixelColor(2, blue); strip.setPixelColor(3, blue); strip.setPixelColor(4, blue); strip.setPixelColor(5, blue); strip.setPixelColor(1, white); //BLANCO strip.setPixelColor(6, white); //BLANCO strip.show(); delay(100); strip.setPixelColor(0, black); //BLANCO strip.setPixelColor(7, black); //BLANCO strip.setPixelColor(2, black); strip.setPixelColor(3, black); strip.setPixelColor(4, black); strip.setPixelColor(5, black); strip.setPixelColor(1, black); //BLANCO strip.setPixelColor(6, black); //BLANCO strip.show(); delay(100); off; } }