Advertisement
Guest User

Untitled

a guest
May 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h>
  4. #endif
  5.  
  6. #define PIN 7
  7. #define Button1 13
  8. #define Button2 12
  9. int buttonState1 = 0;
  10. int buttonState2 =0;
  11. #define NUMPIXELS 5
  12.  
  13. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  14.  
  15. void setup() {
  16.  
  17. Serial.begin(9600);
  18. pinMode (Button1,INPUT);
  19. pinMode (Button2,INPUT);
  20. pinMode (PIN,OUTPUT);
  21. strip.begin();
  22. strip.show();
  23. }
  24.  
  25. void loop(){
  26. buttonState1 =digitalRead(Button1);
  27. buttonState2 =digitalRead(Button2);
  28. //if button1 ON & button2 OFF turn on red color
  29. if (buttonState1 == HIGH && buttonState2 == LOW)
  30. {
  31. for(int i=0;i<NUMPIXELS;i++){
  32.  
  33.  
  34. strip.setPixelColor(i, strip.Color(150,0,0));
  35. strip.show();
  36. }
  37. }
  38. //if button1 OFF & button2 ON turn on green color
  39. else if (buttonState2 == HIGH && buttonState1 == LOW)
  40. {
  41. for(int i=0;i<NUMPIXELS;i++){
  42.  
  43. strip.setPixelColor(i, strip.Color(0,150,0));
  44. strip.show();
  45. }
  46. }
  47. //else turn on blue
  48. else {
  49. for(int i=0;i<NUMPIXELS;i++){
  50.  
  51. strip.setPixelColor(i, strip.Color(0,0,150));
  52. strip.show();
  53. }
  54. }
  55. delay(100);
  56. Serial.println (buttonState1);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement