1

Topic: FastLED on ESP32

Hello,

I'm using RemoteXY for the first time and so far things have been working great but I'm having an issue with using it with FastLED library. It seems that every time the RemoteXY_Handler is called, the lights all switch off.

As part of my troubleshooting, I tried using the regular delay rather than RemoteXY_delay then they will stay on for the duration and when the loop goes back to call the handler, it seems to cause problems.

I also tried a few different GPIO pins in case that would be an issue but it seems to be the same on all the pins I have tried so far.

I'm confident the code to control the lights is good as I have tested it without remotexy and everything seems to be working ok but if I have missed anything, please let me know.

Could anyone suggest why this may be happening please? Thanks in advance


#define REMOTEXY_MODE__ESP32CORE_BLE

#include <BLEDevice.h>

// RemoteXY connection settings 
#define REMOTEXY_BLUETOOTH_NAME "ESP32"


#include <RemoteXY.h>

// RemoteXY GUI configuration  
#pragma pack(push, 1)  
uint8_t RemoteXY_CONF[] =   // 53 bytes
  { 255,2,0,0,0,46,0,17,0,0,0,31,1,106,200,1,1,3,0,1,
  26,6,51,51,0,2,31,83,84,65,82,84,0,3,1,85,103,23,133,2,
  26,129,6,67,36,12,17,76,97,98,101,108,0 };
  
// this structure defines all the variables and events of your control interface 
struct {

    // input variables
  uint8_t button_01; // =1 if button pressed, else =0
  uint8_t select_01; // from 0 to 5

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;   
#pragma pack(pop)
 
/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

#include <FastLED.h>
#define NUM_LEDS 27  
#define DATA_PIN 6
#define sound1 1
CRGB leds[NUM_LEDS];

int state = 0;


void setup() 
{
  RemoteXY_Init ();
  pinMode(DATA_PIN, OUTPUT);
  pinMode(sound1, OUTPUT);
  digitalWrite(sound1, HIGH);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

  Serial.begin(115200); 
  // TODO you setup code
}

void loop() { 

  RemoteXY_Handler ();
  

  if(state!=RemoteXY.select_01){
    state = RemoteXY.select_01;
    switch (state) {
      case 0:
      /*  current position A */
        off();
        break;
      case 1:
      /*  current position B */
        red();
        break;
      case 2:
      /*  current position C */
        yellow();
        break;
      case 3:
      /*  current position D */
        green();
        break;

    }
  }

  if(RemoteXY.button_01 ==1){
    start();
  }
  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay(), use instead RemoteXY_delay() 

}

void start(){
  digitalWrite(sound1, LOW);
  RemoteXY_delay(900);
  digitalWrite(sound1, HIGH);
  for(int i = 0; i<NUM_LEDS; i++){
  if(i<9){
    leds[i] = CRGB::Red;  
  }
  else{leds[i] = CRGB::Black;}
  FastLED.show();
  }
  
  RemoteXY_delay(1000);
  
  for(int i = 0; i<NUM_LEDS; i++){
  if(i<18){
    leds[i] = CRGB::Red;  
  }
  else{leds[i] = CRGB::Black;}
  FastLED.show();
  }
  
  
  
  RemoteXY_delay(900);
  for(int i = 0; i<NUM_LEDS; i++){
    leds[i] = CRGB::Red;
    FastLED.show();
  }
  

  RemoteXY_delay(900);

  for(int i = 0; i<NUM_LEDS; i++){
    leds[i] = CRGB::Green;
    FastLED.show();  
  }
  

  RemoteXY_delay(2000);

  for(int i = 0; i<NUM_LEDS; i++){
  leds[i] = CRGB::Black;
  FastLED.show();
  }

}

void off(){
 for(int i = 0; i<NUM_LEDS; i++){
  leds[i] = CRGB::Black;
  FastLED.show();
  }
}

void red(){
 for(int i = 0; i<NUM_LEDS; i++){
  leds[i] = CRGB::Red;
  FastLED.show();
  }
}

void yellow(){
  for(int i = 0; i<NUM_LEDS; i++){
  leds[i] = CRGB::Yellow;
  FastLED.show(); 
  }
}

void green(){
 for(int i = 0; i<NUM_LEDS; i++){
  leds[i] = CRGB::Green;
  FastLED.show(); 
  }
}