Skip to content

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

Closed
@PilnyTomas

Description

@PilnyTomas

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.

Activity

self-assigned this
on May 20, 2022
igrr

igrr commented on May 20, 2022

@igrr
Member

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

me-no-dev commented on May 20, 2022

@me-no-dev
Member

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

me-no-dev commented on May 20, 2022

@me-no-dev
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

igrr commented on May 20, 2022

@igrr
Member

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

PilnyTomas commented on May 20, 2022

@PilnyTomas
ContributorAuthor

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

added this to the 2.0.4 milestone on Jun 15, 2022

4 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Implement LED_BUILTIN constant + digitalWrite() overload for RGB LED · Issue #6783 · espressif/arduino-esp32