Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h>
  4. #endif
  5.  
  6. // strip connected to pin 6
  7. #define PIN 6
  8.  
  9. // defining strip as instance of neopixel library
  10. Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, 6, NEO_GRB + NEO_KHZ800); // number of pixels, pin number
  11.  
  12. // button 1 connected to pin 7
  13. const int button1 = 7;
  14.  
  15. // button 2 connected to pin 8
  16. const int button2 = 8;
  17.  
  18. // both button states starts at 0 (off)
  19. int button1State = 0;
  20. int button2State = 0;
  21.  
  22. void setup() {
  23. // initialize strip
  24. strip.begin();
  25.  
  26. // sets pixels to 0 (off)
  27. strip.show();
  28.  
  29. // sets buttons as input
  30. pinMode(button1, INPUT);
  31. pinMode(button2, INPUT);
  32. }
  33.  
  34. void loop() {
  35. // reads button state
  36. button1State = digitalRead(button1);
  37. button2State = digitalRead(button2);
  38.  
  39. if((button1State == HIGH) && (button2State == LOW)){ // if button 1 is on (and button 2 is off)
  40. for(uint16_t i = 0; i < strip.numPixels(); i++){
  41. strip.setPixelColor(i, 255, 0, 0); // sets LED colors to red
  42. strip.show(); // shows pixel color
  43. delay(100); //delay of showing
  44. }
  45. }
  46.  
  47. else if((button2State == HIGH) && (button1State == LOW)){ // if button 2 is on (and button 1 is off)
  48. for(uint16_t i = 0; i < strip.numPixels(); i++){
  49. strip.setPixelColor(i, 0, 0, 255); // sets LED colors to blue
  50. strip.show();
  51. delay(100);
  52. }
  53. }
  54.  
  55. else if((button1State == HIGH) && (button2State == HIGH)){
  56. for(uint16_t i = 0; i < strip.numPixels(); i++){
  57. strip.setPixelColor(i, 180, 0, 180); // sets LED colors to purple
  58. strip.show();
  59. delay(100);
  60. }
  61. }
  62.  
  63. else if((button1State == LOW) && (button2State == LOW)){ // if button 1 is off and button 2 is off
  64. for(uint16_t i = 0; i < strip.numPixels(); i++){
  65. strip.setPixelColor(i, 0, 0, 0); // sets LEDs to off
  66. strip.show();
  67. delay(100);
  68. }
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement