Skip to content

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Nov 7, 2023

Description of Change

Based on issue #8841, it was clear that some improvements could be done to the neopixelWrite() function.
Changes:
1- All RMT examples use the PIN_NEOPIXEL defined in pins_arduino.h for the Espressif devkits
2- neopixelWrite() can be used with many GPIOs in the same sketch. Before this changes, the sketch could only use one GPIO with neopixelWrite().

Tests scenarios

Tested with ESP32-C6:

void blinkRGBLED(uint32_t count, uint32_t time_ms) {
  const uint8_t LED_Pin = 23;  // change it to any other valid GPIO
  for ( ; count; count--) {
    neopixelWrite(LED_Pin, 255, 255, 255);  // RGB = White (on)
    Serial.println("HIGH");
    delay(time_ms);
    neopixelWrite(LED_Pin, 0, 0, 0); // RGB = Black (off)
    Serial.println("LOW");
    delay(time_ms);
  }
}

void setup() {
  // No need to initialize the RGB LED
  blinkRGBLED(5, 500);
}

// the loop function runs over and over again forever
void loop() {
#ifdef RGB_BUILTIN
  digitalWrite(RGB_BUILTIN, HIGH);   // Turn the RGB LED white
  delay(1000);
  digitalWrite(RGB_BUILTIN, LOW);    // Turn the RGB LED off
  delay(1000);

  neopixelWrite(PIN_NEOPIXEL, RGB_BRIGHTNESS, 0, 0); // Red
  delay(1000);
  neopixelWrite(PIN_NEOPIXEL, 0, RGB_BRIGHTNESS, 0); // Green
  delay(1000);
  neopixelWrite(PIN_NEOPIXEL, 0, 0, RGB_BRIGHTNESS); // Blue
  delay(1000);
  neopixelWrite(PIN_NEOPIXEL, 0, 0, 0); // Off / black
  delay(1000);
#endif
}

Related links

Fix #8841

The function can now be used for many GPIOs in the same sketch by using Peripheral Manager attach/detach, not being necesary to worry about initialization.
@VojtechBartoska VojtechBartoska added the Status: Pending Merge Pull Request is ready to be merged label Nov 8, 2023
@me-no-dev me-no-dev merged commit de7cac1 into espressif:master Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Status: Pending Merge Pull Request is ready to be merged
Projects
4 participants