Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- #define LED_PIN 6
- const int buttonPin = 2;
- #define LED_COUNT 60
- int buttonState = 0; //set button state LOW
- Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
- void setup() {
- // put your setup code here, to run once:
- #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
- clock_prescale_set(clock_div_1);
- #endif
- strip.begin();
- strip.show();
- strip.setBrightness(50);
- pinMode(buttonPin, INPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- buttonState = digitalRead(buttonPin); //read button state
- if (buttonState == HIGH){ //when button is pressed
- colorWipe(strip.Color(255, 0, 0), 15);//red
- colorWipe(strip.Color(0, 255, 0), 15);//green
- colorWipe(strip.Color(0, 0, 255), 15);//blue
- colorWipe(strip.Color(255,255,0), 15);//yellow
- colorWipe(strip.Color(255, 0,255), 15);//magenta
- colorWipe(strip.Color(0, 255,255), 15);//cyan
- colorWipe(strip.Color(255,255,255),15);//White
- }else { //when button is released
- colorWipe(strip.Color(0,0,0),50); //turn off
- }
- }
- void colorWipe(uint32_t color, int wait) {
- for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
- strip.setPixelColor(i, color); // Set pixel's color (in RAM)
- strip.show(); // Update strip to match
- delay(wait); // Pause for a moment
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement