Skip to content

Implement LED_BUILTIN constant + digitalWrite() overload for RGB LED #6783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
PilnyTomas opened this issue May 20, 2022 · 5 comments · Fixed by #6808
Closed
1 task done

Implement LED_BUILTIN constant + digitalWrite() overload for RGB LED #6783

PilnyTomas opened this issue May 20, 2022 · 5 comments · Fixed by #6808
Assignees
Labels
Status: In Progress ⚠️ Issue is in progress Type: Feature request Feature request for Arduino ESP32
Milestone

Comments

@PilnyTomas
Copy link
Contributor

Related area

RGB LED, Blink example

Hardware specification

C3, S3, dev boards with RGB LED

Is your feature request related to a problem?

No issue found

Describe the solution you'd like

Implement LED_BUILTIN constant for dev boards with RGB LED. Where not applicable print a helpful error message - for example, This board does not have builtin LED instead of default error: 'LED_BUILTIN' was not declared in this scope
For boards with RGB LED overload function void digitalWrite(uint8_t pin, uint8_t val) to activate the RGB LED via the appropriate driver.
Sample use of overloaded function:

digitalWrite(LED_BUILTIN, HIGH); // RGB turns full white
digitalWrite(LED_BUILTIN, LOW); // RGB turns off

// Nice to have (1) - ability to control each channel
digitalWrite(RED_LED_BUILTIN, HIGH); // Red channel full brightness
digitalWrite(GREEN_LED_BUILTIN, HIGH); // Green channel full brightness
digitalWrite(BLUE_LED_BUILTIN, HIGH); // Blue channel full brightness
// Similar for LOW -> channel is off

// Nice to have (2) - ability to control brightness
digitalWrite(RED_LED_BUILTIN, 128); // Red channel turns on to 50% brightness

Describe alternatives you've considered

No response

Additional context

No response

I have checked existing list of Feature requests and the Contribution Guide

  • I confirm I have checked existing list of Feature requests and Contribution Guide.
@igrr
Copy link
Member

igrr commented May 20, 2022

Regarding

// Nice to have (2) - ability to control brightness
digitalWrite(RED_LED_BUILTIN, 128); // Red channel turns on to 50% brightness

TBH it looks a bit odd from Arduino API perspective. How about using analogWrite for this purpose, instead? For a normal GPIO connected to an LED, analogWrite(LED_BUILTIN, value) can be used to control LED brightness by means of a PWM output.

@me-no-dev
Copy link
Member

me-no-dev commented May 20, 2022

This feature is much in line with defining a way for boards to declare what they have on-board. Things like LED, SD/SDMMC, LCD, etc. Also Peripheral Manager :)
Declaring something like (in pins_arduino.h):

#define BOARD_HAS_WS2802
#define LED_BUILTIN 18 // maybe we need to add offset so to not prevent using the pin for normal digitalWrite

Then:

void digitalWrite(uint8_t pin, bool level){
#ifdef BOARD_HAS_WS2802
  if(pin == LED_BUILTIN){
    //use RMT to set all channels on/off
    return;
  }
#endif
  // regular digitalWrite logic
}

@me-no-dev
Copy link
Member

that COLOR_LED_BUILTIN idea look odd overall... how would you define the colors? If the user knows they have RGB, then they can use another API to set the color IMHO.

@igrr
Copy link
Member

igrr commented May 20, 2022

I do agree with @me-no-dev that this should be implemented only to provide compatibility with sketches/libraries which use LED_BUILTIN.

More complex functionality such as setting the color could be handled using a dedicated library (like NeoPixel).

@PilnyTomas
Copy link
Contributor Author

Ok, we can keep it minimalistic and provide only the basic compatibility.

@VojtechBartoska VojtechBartoska added the Status: In Progress ⚠️ Issue is in progress label Jun 14, 2022
@VojtechBartoska VojtechBartoska added this to the 2.0.4 milestone Jun 15, 2022
@VojtechBartoska VojtechBartoska moved this from Todo to In Review in Arduino ESP32 Core Project Roadmap Jun 15, 2022
me-no-dev pushed a commit that referenced this issue Jun 24, 2022
* Initial implementation of RGB driver via digitalWrite

* Moved constants to pins_arduino.h

* Changed pin definition + added example

* Wrapped BlinkRGB in #ifdef BOARD_HAS_NEOPIXEL

* Removed forgotten log from example

* Moved RGBLedWrite to new file esp32-hal-rgb-led and created pinMode in variatn.cpp

* Updated example - lowered single channel brightness to LED_BRIGHTNESS

* Changed function name from RGBLedWrite to neopixelWrite + code polishing

* Moved pinSetup portion related to RGB back to common file
Repository owner moved this from In Review to Done in Arduino ESP32 Core Project Roadmap Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress ⚠️ Issue is in progress Type: Feature request Feature request for Arduino ESP32
Projects
Development

Successfully merging a pull request may close this issue.

4 participants