Advertisement
Guest User

Untitled

a guest
Jan 4th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include <Button.h>
  2. #include <Adafruit_NeoPixel.h>
  3. #ifdef AVR
  4. #include <avr/power.h>
  5. #endif
  6. #define PIN 6
  7.  
  8. Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
  9. Button button1(13); // Connect your button between pin 2 and GND
  10. Button button2(12); // Connect your button between pin 3 and GND
  11. Button button3(11); // Connect your button between pin 4 and GND
  12. Button button4(10);
  13. Button button5(9);
  14. int one=0;
  15. int two=8;
  16. int three=16;
  17. int four=24;
  18. int five=32;
  19.  
  20.  
  21. void setup() {
  22. strip.begin();
  23. strip.setBrightness(25);
  24. strip.show();
  25. button1.begin();
  26. button2.begin();
  27. button3.begin();
  28. button4.begin();
  29. button5.begin();
  30. attachInterrupt(1,clearAll, CHANGE);
  31.  
  32. while (!Serial) { };
  33. Serial.begin(9600);
  34. }
  35.  
  36. void loop() {
  37. if (button1.pressed()){
  38. Serial.println("Button 1 pressed");
  39. if(one<=7){
  40. uint32_t c=strip.Color(255,0,0);
  41. strip.setPixelColor(one,c);
  42. delay(10);
  43. strip.show();
  44. one++;
  45. }
  46. } else if (button2.pressed()){
  47. Serial.println("Button 2 pressed");
  48. if(two<=15 && two>=7){
  49. uint32_t c=strip.Color(255,0,0);
  50. strip.setPixelColor(two,c);
  51. delay(500);
  52. strip.show();
  53. two++;
  54. }
  55. } else if (button3.pressed()){
  56. Serial.println("Button 3 pressed");
  57. if(three<=23 && three>=15){
  58. uint32_t c=strip.Color(255,0,0);
  59. strip.setPixelColor(three,c);
  60. delay(500);
  61. strip.show();
  62. three++;
  63. }
  64. } else if (button4.pressed()){
  65. Serial.println("Button 4 pressed");
  66. if(four<=31 && four>=23){
  67. uint32_t c=strip.Color(255,0,0);
  68. strip.setPixelColor(four,c);
  69. delay(500);
  70. strip.show();
  71. four++;
  72. }
  73. } else if (button5.pressed()){
  74. Serial.println("Button 5 pressed");
  75. if(five<=39 && five>=31){
  76. uint32_t c=strip.Color(255,0,0);
  77. strip.setPixelColor(five,c);
  78. delay(500);
  79. strip.show();
  80. five++;
  81. }
  82. }
  83.  
  84. }
  85.  
  86.  
  87. void clearAll(){
  88. one=0; two=8; three=16; four=24; five=32;
  89. for(int i=0;i<39;i++){
  90. strip.setPixelColor(i, strip.Color(0,0,0));
  91. strip.clear();
  92. strip.show();
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement