Untitled
#include <Adafruit_NeoPixel.h> #define BUTTON_PIN 3 #define LED_PIN 2 #define LED_COUNT 8 #define BRIGHTNESS 255 // variables will change: int buttonState = 0; // variable for reading the pushbutton status Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGBW); void setup() { Serial.begin(9600); // initialize the LED pin as an output: // pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(BUTTON_PIN, INPUT); strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) strip.show(); // Turn OFF all pixels ASAP strip.setBrightness(BRIGHTNESS); pulseWhite(2); } void loop() { // read the state of the pushbutton value: int readButtonState = digitalRead(BUTTON_PIN); if (readButtonState == HIGH && buttonState == LOW) { onButtonClick(); } buttonState = readButtonState; } void onButtonClick() { pulseWhite(1); } void pulseWhite(uint8_t wait) { for(int j=0; j<256;j++) { strip.fill(strip.Color(255, 255, 255, strip.gamma8(j))); strip.show(); delay(1); } delay(wait * 1000); for(int j=255; j>=0; j = j - 1) { // Ramp down from 255 to 0 strip.fill(strip.Color(j, j, j, strip.gamma8(j))); strip.show(); } strip.fill(strip.Color(0,0,0,0)); strip.show(); // for(int j=0; j<256; j++) { // Ramp up from 0 to 255 // // Fill entire strip with white at gamma-corrected brightness level 'j': // strip.fill(strip.Color(0, 0, 0, 255)); // strip.show(); // delay(wait); // } // strip.fill(strip.Color(0, 0, 0, strip.gamma8(0))); // strip.show(); // // for(int j=255; j>=0; j--) { // Ramp down from 255 to 0 // strip.fill(strip.Color(0, 0, 0, 0)); // strip.show(); // delay(wait); // } }
Leave a Comment