Freenove/Freenove_WS2812_Lib_for_ESP32

using RGB_BUILTIN for pin does not work, and will reset the S2 and S3 boards

Closed this issue · 0 comments

KurtE commented

I was experimenting with a couple of ESP boards and was playing with the rainbow example on the built-in RGB led on the boards. When switching between the boards I would at times forget to change the pin number. Then I found they had defined RGB_BUILTIN which looked promising, but, when I tried it, the LED did not work and on the S2 and S3 it would GURU Meditate, in the call to strip.begin().

#include "Freenove_WS2812_Lib_for_ESP32.h"

#define LEDS_COUNT 1
#define CHANNEL 0
Freenove_ESP32_WS2812 strip = Freenove_ESP32_WS2812(LEDS_COUNT, RGB_BUILTIN , CHANNEL, TYPE_GRB);

void setup() {
  strip.begin();
  strip.setBrightness(20);
}

void loop() {
  for (int j = 0; j < 255; j += 2) {
    for (int i = 0; i < LEDS_COUNT; i++) {
      strip.setLedColorData(i, strip.Wheel((i * 256 / LEDS_COUNT + j) & 255));
    }
    strip.show();
    delay(10);
  }
}

I posted on the ESP32 forum and a possible fix was suggested, which I first tried locally in the sketch, and then tried a variation of it in your library.

I put the change into the constructor, could have gone in the begin method.

Freenove_ESP32_WS2812::Freenove_ESP32_WS2812(u16 n /*= 8*/, u8 pin_gpio /*= 2*/, u8 chn /*= 0*/, LED_TYPE t /*= TYPE_GRB*/)
{
	ledCounts = n;
	pin = pin_gpio;
#ifdef RGB_BUILTIN
  	if((pin == RGB_BUILTIN) && (RGB_BUILTIN > SOC_GPIO_PIN_COUNT)){
    	pin -= SOC_GPIO_PIN_COUNT;
  }
#endif
	rmt_chn = chn;
	rmt_mem = RMT_MEM_64;
	br = 255;
	setLedType(t);
}

The new stuff was the stuff within the #ifdef
I added the check for RGB_BUILTIN > SOC_GPIO_PIN_COUNT on the off chance that someone actually defines the constant to be the actual pin.