Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Button.h>
- #include <Adafruit_NeoPixel.h>
- #ifdef AVR
- #include <avr/power.h>
- #endif
- #define PIN 6
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
- Button button1(13); // Connect your button between pin 2 and GND
- Button button2(12); // Connect your button between pin 3 and GND
- Button button3(11); // Connect your button between pin 4 and GND
- Button button4(10);
- Button button5(9);
- int one=0;
- int two=8;
- int three=16;
- int four=24;
- int five=32;
- void setup() {
- strip.begin();
- strip.setBrightness(25);
- strip.show();
- button1.begin();
- button2.begin();
- button3.begin();
- button4.begin();
- button5.begin();
- attachInterrupt(1,clearAll, CHANGE);
- while (!Serial) { };
- Serial.begin(9600);
- }
- void loop() {
- if (button1.pressed()){
- Serial.println("Button 1 pressed");
- if(one<=7){
- uint32_t c=strip.Color(255,0,0);
- strip.setPixelColor(one,c);
- delay(10);
- strip.show();
- one++;
- }
- } else if (button2.pressed()){
- Serial.println("Button 2 pressed");
- if(two<=15 && two>=7){
- uint32_t c=strip.Color(255,0,0);
- strip.setPixelColor(two,c);
- delay(500);
- strip.show();
- two++;
- }
- } else if (button3.pressed()){
- Serial.println("Button 3 pressed");
- if(three<=23 && three>=15){
- uint32_t c=strip.Color(255,0,0);
- strip.setPixelColor(three,c);
- delay(500);
- strip.show();
- three++;
- }
- } else if (button4.pressed()){
- Serial.println("Button 4 pressed");
- if(four<=31 && four>=23){
- uint32_t c=strip.Color(255,0,0);
- strip.setPixelColor(four,c);
- delay(500);
- strip.show();
- four++;
- }
- } else if (button5.pressed()){
- Serial.println("Button 5 pressed");
- if(five<=39 && five>=31){
- uint32_t c=strip.Color(255,0,0);
- strip.setPixelColor(five,c);
- delay(500);
- strip.show();
- five++;
- }
- }
- }
- void clearAll(){
- one=0; two=8; three=16; four=24; five=32;
- for(int i=0;i<39;i++){
- strip.setPixelColor(i, strip.Color(0,0,0));
- strip.clear();
- strip.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement