#define btn1 16 #define btn2 27 #include #ifdef __AVR__ #include // Required for 16 MHz Adafruit Trinket #endif // Which pin on the Arduino is connected to the NeoPixels? // On a Trinket or Gemma we suggest changing this to 1: #define LED_PIN 26 // How many NeoPixels are attached to the Arduino? #define LED_COUNT 4 // Declare our NeoPixel strip object: Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); int btn_count = 0; //Used to count the clicked button times void setup() { Serial.begin(9600); pinMode(btn1, INPUT); pinMode(btn2, INPUT); #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // END of Trinket-specific code. strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) strip.show(); // Turn OFF all pixels ASAP strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) } void loop() { boolean btn1_val = digitalRead(btn1); boolean btn2_val = digitalRead(btn2); if(btn1_val == 0) //If the button is pressed { delay(10); //Delay 10ms to eliminate button jitter if(btn1_val == 0) //Make sure the button is pressed again { boolean btn_state = 1; while(btn_state == 1) //Loop indefinitely until the button is released { boolean btn_val = digitalRead(btn1); if(btn_val == 1) //If the button is released { btn_count--; //Automatically increments by 1 to count the clicked button times if(btn_count <= 0) { btn_count = 0; } Serial.println(btn_count); btn_state = 0; //The button is released and exits the loop } } } } if(btn2_val == 0) //If the button is pressed { delay(10); //Delay 10ms to eliminate button jitter if(btn2_val == 0) //Make sure the button is pressed again { boolean btn_state2 = 1; while(btn_state2 == 1) //Loop indefinitely until the button is released { boolean btn2_val = digitalRead(btn2); if(btn2_val == 1) //If the button is released { btn_count++; //Automatically increments by 1 to count the clicked button times if(btn_count >= 6) { btn_count = 6; } Serial.println(btn_count); btn_state2 = 0; //The button is released and exits the loop } } } } switch(btn_count) { case 0: colorWipe(strip.Color(0, 0, 0), 50); break; case 1: colorWipe(strip.Color(255, 0, 0), 50); break; case 2: colorWipe(strip.Color(0, 255, 0), 50); break; case 3: colorWipe(strip.Color(0, 0, 255), 50); break; case 4: colorWipe(strip.Color(255, 255, 0), 50); break; case 5: colorWipe(strip.Color(255, 0, 255), 50); break; case 6: colorWipe(strip.Color(255, 255, 255), 50); break; } } void colorWipe(uint32_t color, int wait) { for(int i=0; i