title: FastLED.h blocks ezButton.h
body: <p>I'm using Arduino to control a project which contains addressable LEDs and buttons.
  The libraries I'm using are in the title.
  For an unknown reason, when I use each code separately everything works fine, but when I combine them the FastLED library blocks the button reading and causes weird things - like giving double press, or stop doing other things.</p>
  <p>How can I fix the issue? (I tried to eliminate the delay(), but it wasn't helpful)
  Thanks in advance!</p>
  <pre><code>/*
    Author: Yuval Kedar - KD Technology
    Instagram: https://www.instagram.com/kd_technology/
    Date: Oct 19
    Dev board: Arduino Uno
    
      There are two button types: Red and Blue.
      Red btn = -1
      Blue btn = +1
  
      On the machine's background there is an LED matrix which shows the user's progress.
      There are 4 levels (square frames) until one reaches the core and wins.
  
      The trick? The floor, which includes the buttons, is spinning.
  */
  
  #include &lt;FastLED.h&gt;
  #include &lt;ezButton.h&gt;
  #include &quot;Arduino.h&quot;
  
  #define WINNING_SENSOR_PIN (12)
  #define LED_DATA_PIN (6)
  #define BLUE_BTN_PIN (A0)
  #define RED_BTN_PIN (A3)
  
  #define SERIAL_BAUDRATE (115200)
  #define NUM_LEDS (64)
  #define LED_BRIGHTNESS (200)
  #define WINNING_FX_TIME (1000)
  
  ezButton blue_btn(BLUE_BTN_PIN);
  ezButton red_btn(RED_BTN_PIN);
  CRGB leds[NUM_LEDS];
  
  uint8_t score = 0;
  uint8_t last_score = 0;
  uint8_t level[] = {0, 28, 48, 60, 63};  //levels 0 to 4
  
  void level_up(uint8_t led_num) {
      uint8_t start_point = 0;
      if (led_num == level[1]) start_point = 0;   //up from level 0 to 1
      if (led_num == level[2]) start_point = 28;  //up from level 1 to 2
      if (led_num == level[3]) start_point = 48;  //up from level 2 to 3
      if (led_num == level[4]) start_point = 60;  //...
  
      for (uint8_t current_pixel = start_point; current_pixel &lt; led_num; current_pixel++) {
          leds[current_pixel] = CRGB::Blue;
          FastLED.show();
          delay(50);
      }
      delay(2500); //debounce
  }
  
  void level_down(uint8_t led_num) {  //clear prev level's frame and do the opposite direction effect with red color
      uint8_t start_point = 0;
      if (led_num == level[0]) start_point = 28;  //down from level 1 to 0
      if (led_num == level[1]) start_point = 48;  //down from level 2 to 1
      if (led_num == level[2]) start_point = 60;  //down from level 3 to 2
      if (led_num == level[3]) start_point = 63;  //...
  
      for (int8_t i = start_point - 1; i &gt; led_num; i--) {
          leds[i] = CRGB::Red;
          FastLED.show();
          delay(50);
      }
      for (int8_t i = start_point - 1; i &gt; led_num; i--) {
          leds[i] = CRGB::Black;
          FastLED.show();
      }
      delay(2500); //debounce
  }
  
  void fadeall() {
      for(uint8_t i = 0; i &lt; NUM_LEDS; i++) {
          leds[i].nscale8(250);
      }
  }
  
  void winning() {
      static uint8_t hue = 0;
      for(uint8_t x = 0; x &lt; 5; x++) {
          for(int8_t i = 0; i &lt; NUM_LEDS; i++) {
              leds[i] = CHSV(hue++, 255, 255);
              FastLED.show(); 
              fadeall();
              // delay(10);
          }
          for(int8_t i = (NUM_LEDS)-1; i &gt;= 0; i--) {
              leds[i] = CHSV(hue++, 255, 255);
              FastLED.show();
              fadeall();
              // delay(10);
          }
      }
      
  }
  
  void reset_game() {
      score = 0;
      last_score = 4;
      digitalWrite(WINNING_SENSOR_PIN, LOW);
      FastLED.clear();
      FastLED.show();}
  
  void winning_check() {
      (score == 4) ? analogWrite(WINNING_SENSOR_PIN, 175) : digitalWrite(WINNING_SENSOR_PIN, LOW);
  }
  
  void update_score() {
      if (blue_btn.isPressed()) {
          Serial.println(&quot;+PLUS+&quot;);
          if (score++ &gt;= 4) score = 4;
      }
  
      if (red_btn.isPressed()) {
          Serial.println(&quot;-MINUS-&quot;);
          if (score-- &lt;= 0) score = 0;
      }
  
      if (score == 0){
          if (last_score == 1) level_down(level[0]);
          last_score = 0;
          digitalWrite(WINNING_SENSOR_PIN, LOW);
      }
      else if (score == 1) {
          if (last_score == 0) level_up(level[1]);    // if last_score was 0 make the blue effect because level is up
          if (last_score == 2) level_down(level[1]);  // if last_score was 2 make the red effect because level is down
          last_score = 1;
          digitalWrite(WINNING_SENSOR_PIN, LOW);
      }
      else if (score == 2) {
          if (last_score == 1) level_up(level[2]);
          if (last_score == 3) level_down(level[2]);
          last_score = 2;
          digitalWrite(WINNING_SENSOR_PIN, LOW);
      }
      else if (score == 3) {
          if (last_score == 2) level_up(level[3]);
          if (last_score == 4) level_down(level[3]);
          last_score = 3;
          digitalWrite(WINNING_SENSOR_PIN, LOW);
      }
      else if (score == 4) {
          winning_check();
          // winning();  //this func makes issue when using ezButton.h. It calls &quot;show&quot; too many times.
          reset_game();
      }
  }
  
  void setup() {
      Serial.begin(SERIAL_BAUDRATE);
  
      pinMode(WINNING_SENSOR_PIN, OUTPUT);
      digitalWrite(WINNING_SENSOR_PIN, LOW);
  
      blue_btn.setDebounceTime(150);
      red_btn.setDebounceTime(150);
  
      FastLED.addLeds&lt;NEOPIXEL, LED_DATA_PIN&gt;(leds, NUM_LEDS);  // GRB ordering is assumed
      FastLED.setBrightness(LED_BRIGHTNESS);
      FastLED.clear();
      FastLED.show();
  
  
      Serial.println(F(
          &quot;_______________________________\n&quot;
          &quot;\n&quot;
          &quot;   G e a r   M a c h i n e     \n&quot;
          &quot;_______________________________\n&quot;
          &quot;\n&quot;
          &quot;   ~ Made by KD Technology ~   \n&quot;
          &quot;\n&quot;));
  }
  
  void loop() {
      blue_btn.loop();
      red_btn.loop();
      Serial.println(score);
  
      update_score();
      FastLED.show();
  }
  
  </code></pre>