<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[RemoteXY community — FastLED on ESP32]]></title>
	<link rel="self" href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=1800&amp;type=atom" />
	<updated>2024-05-08T21:51:19Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.remotexy.com/viewtopic.php?id=1800</id>
		<entry>
			<title type="html"><![CDATA[FastLED on ESP32]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=5524#p5524" />
			<content type="html"><![CDATA[<p>Hello,</p><p>I&#039;m using RemoteXY for the first time and so far things have been working great but I&#039;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. </p><p>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.</p><p>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.</p><p>I&#039;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.</p><p>Could anyone suggest why this may be happening please? Thanks in advance</p><br /><div class="codebox"><pre><code>#define REMOTEXY_MODE__ESP32CORE_BLE

#include &lt;BLEDevice.h&gt;

// RemoteXY connection settings 
#define REMOTEXY_BLUETOOTH_NAME &quot;ESP32&quot;


#include &lt;RemoteXY.h&gt;

// 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 &lt;FastLED.h&gt;
#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&lt;WS2812B, DATA_PIN, GRB&gt;(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&lt;NUM_LEDS; i++){
  if(i&lt;9){
    leds[i] = CRGB::Red;  
  }
  else{leds[i] = CRGB::Black;}
  FastLED.show();
  }
  
  RemoteXY_delay(1000);
  
  for(int i = 0; i&lt;NUM_LEDS; i++){
  if(i&lt;18){
    leds[i] = CRGB::Red;  
  }
  else{leds[i] = CRGB::Black;}
  FastLED.show();
  }
  
  
  
  RemoteXY_delay(900);
  for(int i = 0; i&lt;NUM_LEDS; i++){
    leds[i] = CRGB::Red;
    FastLED.show();
  }
  

  RemoteXY_delay(900);

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

  RemoteXY_delay(2000);

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

}

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

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

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

void green(){
 for(int i = 0; i&lt;NUM_LEDS; i++){
  leds[i] = CRGB::Green;
  FastLED.show(); 
  }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[hashiriya]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2770</uri>
			</author>
			<updated>2024-05-08T21:51:19Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=5524#p5524</id>
		</entry>
</feed>
