Fixes and improvements for PWM pins (#13383)

This commit is contained in:
Scott Lahteine
2019-03-13 06:51:15 -05:00
committed by GitHub
parent 87162658c4
commit f89b375fb9
26 changed files with 196 additions and 193 deletions

View File

@ -61,11 +61,11 @@ LEDLights leds;
void LEDLights::setup() {
#if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
SET_OUTPUT(RGB_LED_R_PIN);
SET_OUTPUT(RGB_LED_G_PIN);
SET_OUTPUT(RGB_LED_B_PIN);
if (PWM_PIN(RGB_LED_R_PIN)) SET_PWM(RGB_LED_R_PIN); else SET_OUTPUT(RGB_LED_R_PIN);
if (PWM_PIN(RGB_LED_G_PIN)) SET_PWM(RGB_LED_G_PIN); else SET_OUTPUT(RGB_LED_G_PIN);
if (PWM_PIN(RGB_LED_B_PIN)) SET_PWM(RGB_LED_B_PIN); else SET_OUTPUT(RGB_LED_B_PIN);
#if ENABLED(RGBW_LED)
SET_OUTPUT(RGB_LED_W_PIN);
if (PWM_PIN(RGB_LED_W_PIN)) SET_PWM(RGB_LED_W_PIN); else SET_OUTPUT(RGB_LED_W_PIN);
#endif
#endif
#if ENABLED(NEOPIXEL_LED)
@ -112,16 +112,12 @@ void LEDLights::set_color(const LEDColor &incol
// This variant uses 3-4 separate pins for the RGB(W) components.
// If the pins can do PWM then their intensity will be set.
WRITE(RGB_LED_R_PIN, incol.r ? HIGH : LOW);
WRITE(RGB_LED_G_PIN, incol.g ? HIGH : LOW);
WRITE(RGB_LED_B_PIN, incol.b ? HIGH : LOW);
analogWrite(RGB_LED_R_PIN, incol.r);
analogWrite(RGB_LED_G_PIN, incol.g);
analogWrite(RGB_LED_B_PIN, incol.b);
#define UPDATE_RGBW(C,c) do{ if (PWM_PIN(RGB_LED_##C##_PIN)) ANALOG_WRITE(RGB_LED_##C##_PIN, incol.r); else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
UPDATE_RGBW(R,r);
UPDATE_RGBW(G,g);
UPDATE_RGBW(B,b);
#if ENABLED(RGBW_LED)
WRITE(RGB_LED_W_PIN, incol.w ? HIGH : LOW);
analogWrite(RGB_LED_W_PIN, incol.w);
UPDATE_RGBW(W,w);
#endif
#endif