Skip to content

Commit

Permalink
ESP32: Using RGB_BUILTIN define as pin number in the constructor fail…
Browse files Browse the repository at this point in the history
…s and resets S2 and S3

I was experimenting with a few different ESP32 boards (C3, S2, S3) and was playing with the on board neopixel and got tired of changing the pin number (C3->8, S2->18, S3->48), and noticed they had a define RGB_BUILTIN and hoped that you could use it in the constructor.

The neopixel failed to work, and on the S2 and S3 it guru-meditated.  Found out they set these values as the pin number plus the count of pins...

So in setPin I checked for this and offset back to the actual pin number.
  • Loading branch information
KurtE committed Jun 29, 2023
1 parent fe882b8 commit c7252ff
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Adafruit_NeoPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,12 @@ if(is800KHz) {
@param p Arduino pin number (-1 = no pin).
*/
void Adafruit_NeoPixel::setPin(int16_t p) {
#if defined(ESP32) && defined(RGB_BUILTIN)
if((p == RGB_BUILTIN) && (RGB_BUILTIN > SOC_GPIO_PIN_COUNT)){
p -= SOC_GPIO_PIN_COUNT;
}
#endif

if (begun && (pin >= 0))
pinMode(pin, INPUT); // Disable existing out pin
pin = p;
Expand Down

0 comments on commit c7252ff

Please sign in to comment.