Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Qinxinrui Zhu. NeoPixel Assignment. Nov.12.2019.//
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
- #endif
- #define LED_PIN 6 // connect to NeoPixels
- #define LED_COUNT 40 // How many Pixels
- #define BUTTON_PIN 2 // connect to button
- boolean oldState = HIGH;
- int mode = 0;//animation mode, 0-9
- 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)
- void setup() {
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
- clock_prescale_set(clock_div_1);
- #endif
- strip.begin();//Initializing the neopxel strip object
- strip.show();// Initialize all pixels to 'off'
- }
- void loop() {
- ////Gets the current button status.
- boolean newState = digitalRead(BUTTON_PIN);
- if ((newState == LOW) && (oldState == HIGH)) {
- // Short delay to debounce button.
- delay(30);
- // Check if the button is still low after debounce.
- newState = digitalRead(BUTTON_PIN);
- if (newState == LOW) {
- if (++mode > 5) mode = 0;
- switch (mode) {
- case 1:
- ////Fill with various colors along the strip
- colorWipe(strip.Color(30, 144, 255), 40);
- break;//DodgerBlue
- case 2 :
- colorWipe(strip.Color(255, 127, 80), 10);//Coral
- break;
- case 3:
- colorWipe(strip.Color(0, 255, 0), 50);//Lime
- break;
- }
- }
- }
- //Set the last read button state to the old state.
- oldState = newState;
- }
- //Created animatied effect
- void colorWipe(uint32_t color, int wait) {
- for (int i = 0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, color);
- strip.show();
- delay(20);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement