Skip to content
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

Improve RGB Driver #6968

Closed
1 task done
santaimpersonator opened this issue Jul 11, 2022 · 5 comments · Fixed by #6979
Closed
1 task done

Improve RGB Driver #6968

santaimpersonator opened this issue Jul 11, 2022 · 5 comments · Fixed by #6979
Assignees
Labels
Status: Solved Type: Feature request Feature request for Arduino ESP32
Milestone

Comments

@santaimpersonator
Copy link
Contributor

santaimpersonator commented Jul 11, 2022

Related area

Implement RGB_BUILTIN variable for (#6808)

Hardware specification

Boards with standard LED and RGB LED

Is your feature request related to a problem?

With the implemented solution (#6808) to issue #6783, users are limited to only controlling a regular LED or RGB LED. Boards with both types of LEDs are now constrained to only utilizing one as the built-in LED.

Describe the solution you'd like

Define a new variable RGB_BUILTIN for the new RGB driver feature (#6808)

  • Replaces the use of the LED_BUILTIN variable in the implementation
  • Removes the need for BOARD_HAS_NEOPIXEL
  • Also, rename LED_BRIGHTNESS to match new variable name RGB_BRIGHTNESS
static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+2;
#define BUILTIN_LED  LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN
#define RGB_BUILTIN LED_BUILTIN
#define RGB_BRIGHTNESS 65

This way users that have a regular LED and RGB LED, will be able to utilize the digitalWrite functionality on both LEDs. Also, the Blink.ino and BlinkRGB.ino example sketches could operate on the LEDs separately.

static const uint8_t LED_BUILTIN = 13;
static const uint8_t RGB_BUILTIN = SOC_GPIO_PIN_COUNT+2;
#define BUILTIN_LED  LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN
#define RGB_BUILTIN RGB_BUILTIN
#define RGB_BRIGHTNESS 65

Affected files/lines of code:

I've tested the proposed changes with the regular Blink.ino and BlinkRGB.ino example sketches, with the following pin definitions:

  • Regular and RGB LED:
    static const uint8_t LED_BUILTIN = 13;
    static const uint8_t RGB_BUILTIN = SOC_GPIO_PIN_COUNT+2;
    #define BUILTIN_LED  LED_BUILTIN // backward compatibility
    #define LED_BUILTIN LED_BUILTIN
    #define RGB_BUILTIN RGB_BUILTIN
    #define RGB_BRIGHTNESS 65
    
  • Only RGB LED:
    static const uint8_t LED_BUILTIN = SOC_GPIO_PIN_COUNT+2;
    #define BUILTIN_LED  LED_BUILTIN // backward compatibility
    #define LED_BUILTIN LED_BUILTIN
    #define RGB_BUILTIN LED_BUILTIN
    #define RGB_BRIGHTNESS 65
    
  • Only regular LED:
    static const uint8_t LED_BUILTIN = 13;
    #define BUILTIN_LED  LED_BUILTIN // backward compatibility
    #define LED_BUILTIN LED_BUILTIN
    

Both sketches operate as expected.

Describe alternatives you've considered

No response

Additional context

I have a pull request ready; however, I thought that I'd start with creating a feature request first.

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.
@santaimpersonator santaimpersonator added the Type: Feature request Feature request for Arduino ESP32 label Jul 11, 2022
@santaimpersonator santaimpersonator changed the title Improve RGB Driver (https://github.com/espressif/arduino-esp32/pull/6808) Improve RGB Driver (#6808) Jul 11, 2022
@santaimpersonator santaimpersonator changed the title Improve RGB Driver (#6808) Improve RGB Driver Jul 11, 2022
@JimDrewGH
Copy link

Instead of having RGB_BRIGHTNESS, I might suggest using RGB_COLOR (rr, gg, bb). That would give you complete control of the brightness as well as the color.

@santaimpersonator
Copy link
Contributor Author

Instead of having RGB_BRIGHTNESS, I might suggest using RGB_COLOR (rr, gg, bb). That would give you complete control of the brightness as well as the color.

@JimDrewGH
While I am open to this suggestion, I don't think it is necessary. Users can easily implement their own variable (such as RGB_COLOR) to control the brightness/color in their sketch. I believe the original intention of the brightness variable is in its simplicity:

  • Provide a default brightness level for the RGB LED
  • Control the default RGB LED brightness for the digitalWrite() function in the Blink.ino built-in example code
  • Control the default RGB LED brightness for the digitalWrite() function and demonstrate color control with the neopixelWrite() function in the BlinkRGB.ino built-in example code

Please, feel free to elaborate further on your suggestion.

@SuGlider
Copy link
Collaborator

@PilnyTomas - PTAL, thanks.

@JimDrewGH
Copy link

JimDrewGH commented Jul 12, 2022

I do like the simplicity of the OP's proposal. Maybe to keep it simple you could have some options like RGB_BUILTIN_BLUE that could be used with the simple digitalWrite() function. This way you could at least have a different color other than WHITE. :)

@PilnyTomas
Copy link
Contributor

Hi @JimDrewGH, the color can be controlled by using neopixelWrite found here
As you can see in proposal #6808 I wanted the option for digitalWrite to be able to control separate color channels as if it was discreet LED, however, this idea was abandoned for the sake of simplicity of usage.
@santaimpersonator If you have already the changes and they work, please create a pull request.

@VojtechBartoska VojtechBartoska added the Status: In Progress Issue is in progress label Jul 13, 2022
@VojtechBartoska VojtechBartoska added this to the 2.0.5 milestone Jul 13, 2022
VojtechBartoska added a commit that referenced this issue Jul 18, 2022
* Improve RGB LED Driver

Replaces the use of the `LED_BUILTIN` variable by creating a new variable called `RGB_BUILTIN`. On boards with both a regular LED and RGB LED, this change provides functionality to control either LED.

The `LED_BRIGHTNESS` variable is changed to `RGB_BRIGHTNESS`, which aligns more closely with the `RGB_BUILTIN` variable name.

`BOARD_HAS_NEOPIXEL` is no longer necessary; it is replaced by `RGB_BUILTIN`.

* Update BlinkRGB example

Update example code for changes with the RGB driver:
- Replace `LED_BUILTIN` and `BOARD_HAS_NEOPIXEL` with `RGB_BUILTIN`
- Replace `LED_BRIGHTNESS` with `RGB_BRIGHTNESS`

* Update board variants

Update board variants for changes with the RGB driver:
- Remove `BOARD_HAS_NEOPIXEL`
- Define `RGB_BUILTIN` pin
- Replace `LED_BRIGHTNESS` with `RGB_BRIGHTNESS` to align with `RGB_BUILTIN` name

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
Co-authored-by: Vojtěch Bartoška <76958047+VojtechBartoska@users.noreply.github.com>
@VojtechBartoska VojtechBartoska added Status: Solved and removed Status: In Progress Issue is in progress labels Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Solved Type: Feature request Feature request for Arduino ESP32
Projects
Development

Successfully merging a pull request may close this issue.

5 participants