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 PIN 7
- #define Button1 13
- #define Button2 12
- int buttonState1 = 0;
- int buttonState2 =0;
- #define NUMPIXELS 5
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- void setup() {
- Serial.begin(9600);
- pinMode (Button1,INPUT);
- pinMode (Button2,INPUT);
- pinMode (PIN,OUTPUT);
- strip.begin();
- strip.show();
- }
- void loop(){
- buttonState1 =digitalRead(Button1);
- buttonState2 =digitalRead(Button2);
- //if button1 ON & button2 OFF turn on red color
- if (buttonState1 == HIGH && buttonState2 == LOW)
- {
- for(int i=0;i<NUMPIXELS;i++){
- strip.setPixelColor(i, strip.Color(150,0,0));
- strip.show();
- }
- }
- //if button1 OFF & button2 ON turn on green color
- else if (buttonState2 == HIGH && buttonState1 == LOW)
- {
- for(int i=0;i<NUMPIXELS;i++){
- strip.setPixelColor(i, strip.Color(0,150,0));
- strip.show();
- }
- }
- //else turn on blue
- else {
- for(int i=0;i<NUMPIXELS;i++){
- strip.setPixelColor(i, strip.Color(0,0,150));
- strip.show();
- }
- }
- delay(100);
- Serial.println (buttonState1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement