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
- // strip connected to pin 6
- #define PIN 6
- // defining strip as instance of neopixel library
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, 6, NEO_GRB + NEO_KHZ800); // number of pixels, pin number
- // button 1 connected to pin 7
- const int button1 = 7;
- // button 2 connected to pin 8
- const int button2 = 8;
- // both button states starts at 0 (off)
- int button1State = 0;
- int button2State = 0;
- void setup() {
- // initialize strip
- strip.begin();
- // sets pixels to 0 (off)
- strip.show();
- // sets buttons as input
- pinMode(button1, INPUT);
- pinMode(button2, INPUT);
- }
- void loop() {
- // reads button state
- button1State = digitalRead(button1);
- button2State = digitalRead(button2);
- if((button1State == HIGH) && (button2State == LOW)){ // if button 1 is on (and button 2 is off)
- for(uint16_t i = 0; i < strip.numPixels(); i++){
- strip.setPixelColor(i, 255, 0, 0); // sets LED colors to red
- strip.show(); // shows pixel color
- delay(100); //delay of showing
- }
- }
- else if((button2State == HIGH) && (button1State == LOW)){ // if button 2 is on (and button 1 is off)
- for(uint16_t i = 0; i < strip.numPixels(); i++){
- strip.setPixelColor(i, 0, 0, 255); // sets LED colors to blue
- strip.show();
- delay(100);
- }
- }
- else if((button1State == HIGH) && (button2State == HIGH)){
- for(uint16_t i = 0; i < strip.numPixels(); i++){
- strip.setPixelColor(i, 180, 0, 180); // sets LED colors to purple
- strip.show();
- delay(100);
- }
- }
- else if((button1State == LOW) && (button2State == LOW)){ // if button 1 is off and button 2 is off
- for(uint16_t i = 0; i < strip.numPixels(); i++){
- strip.setPixelColor(i, 0, 0, 0); // sets LEDs to off
- strip.show();
- delay(100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement