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

Enhancement for PWM'd RGB LED #200

Open
noeldodd opened this issue Sep 11, 2024 · 1 comment
Open

Enhancement for PWM'd RGB LED #200

noeldodd opened this issue Sep 11, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@noeldodd
Copy link

noeldodd commented Sep 11, 2024

I'd like to be able to dim my projects RGB LED during the night.

Any interest in something like this? Or does it exist and I just missed it?

// Move to json files:
#define PWM_R_CHANNEL 4
#define PWM_G_CHANNEL 5
#define PWM_B_CHANNEL 6
#define PWM_FREQ 5000
#define PWM_RESOLUTION 8

void setup() {
  ledcSetup(PWM_R_CHANNEL, PWM_FREQ, PWM_RESOLUTION);
  ledcSetup(PWM_G_CHANNEL, PWM_FREQ, PWM_RESOLUTION);
  ledcSetup(PWM_B_CHANNEL, PWM_FREQ, PWM_RESOLUTION);
  ledcAttachPin(RGB_LED_R,PWM_R_CHANNEL);
  ledcAttachPin(RGB_LED_G,PWM_G_CHANNEL);
  ledcAttachPin(RGB_LED_B,PWM_B_CHANNEL);
  //...
}

void smartdisplay_led_set_pwmrgb(byte r, byte g, byte b)
{
  // log_d("R:%d, G:%d, B:%d", r, g, b);
  ledcWrite(RGB_LED_R,r);
  ledcWrite(RGB_LED_G, g);
  ledcWrite(RGB_LED_B, b);
}

I looked at the source and rather than these #defines it looks like they are -D's in each boards .json definition.

Also, I have absolutely ZERO idea if those PWM channels are in use, optimal (ie minimal) freq/resolution values, or if there is a workable automatic way to let LEDC decide which to use, etc.

But I've tested this as-is, and works.

ALSO: The log statement in your smartdisplay_led_set_rgb has a typo, you output 'g' twice :)

(Edited to post correct code)

@rzeldent rzeldent self-assigned this Sep 14, 2024
@rzeldent rzeldent added the enhancement New feature or request label Sep 14, 2024
@rzeldent
Copy link
Owner

Hi Noel,

Thanks for pointing out the typo. Although small, is fixed in current develop.

The channels can indeed be defined in the definition files, the point is that, as you already pointed out, these PWM channels might already be in use. So that's why this was not implemented using RGB.

If you'd like to have this functionality, please make a pull request and make a function to initialize this with the PWM channels and a function to set the value. This is indeed a nice to have!

Kind regards,

Rene

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants