diff --git a/src/src/extras/PwmPin.cpp b/src/src/extras/PwmPin.cpp index b019dfd..404105f 100644 --- a/src/src/extras/PwmPin.cpp +++ b/src/src/extras/PwmPin.cpp @@ -102,7 +102,7 @@ LedPin::LedPin(uint8_t pin, float level, uint16_t freq, boolean invert) : LedC(p /////////////////// -void LedPin::set(float level){ +void LedPin::set(float level, uint32_t fadeTime){ if(!channel) return; @@ -110,25 +110,14 @@ void LedPin::set(float level){ if(level>100) level=100; - float d=level*(pow(2,(int)timer->duty_resolution)-1)/100.0; - - channel->duty=d; - ledc_channel_config(channel); -} + float d=level*(pow(2,(int)timer->duty_resolution)-1)/100.0; -/////////////////// - -void LedPin::fade(float level, uint32_t fadeTime){ - - if(!channel) - return; - - if(level>100) - level=100; - - float d=level*(pow(2,(int)timer->duty_resolution)-1)/100.0; - - ledc_set_fade_time_and_start(channel->speed_mode,channel->channel,(uint32_t)d,fadeTime,LEDC_FADE_NO_WAIT); + if(fadeTime==0){ + channel->duty=d; + ledc_channel_config(channel); + } else { + ledc_set_fade_time_and_start(channel->speed_mode,channel->channel,(uint32_t)d,fadeTime,LEDC_FADE_NO_WAIT); + } } /////////////////// diff --git a/src/src/extras/PwmPin.h b/src/src/extras/PwmPin.h index 68751ca..b6c6452 100644 --- a/src/src/extras/PwmPin.h +++ b/src/src/extras/PwmPin.h @@ -76,8 +76,7 @@ class LedPin : public LedC { public: LedPin(uint8_t pin, float level=0, uint16_t freq=DEFAULT_PWM_FREQ, boolean invert=false); // assigns pin to be output of one of 16 PWM channels initial level and frequency - void set(float level); // sets the PWM duty to level (0-100) - void fade(float level, uint32_t fadeTime); // sets the PWM duty to level (0-100) within fadeTime in milliseconds + void set(float level, uint32_t fadeTime=0); // sets the PWM duty to level (0-100) within fadeTime in milliseconds static void HSVtoRGB(float h, float s, float v, float *r, float *g, float *b ); // converts Hue/Saturation/Brightness to R/G/B }; diff --git a/src/src/extras/extras.ino b/src/src/extras/extras.ino index a982c54..43b2fbd 100644 --- a/src/src/extras/extras.ino +++ b/src/src/extras/extras.ino @@ -38,9 +38,13 @@ void setup() { Serial.println("\n\nHomeSpan LED Fade Test\n"); - LedPin led(26,50); + LedPin led(26); + for(int i=10;i<=100;i+=10){ + led.set(i); + delay(1000); + } Serial.printf("Start\n"); - led.fade(0,10000); + led.set(0,5000); Serial.printf("End\n"); while(1);