Begin implementation of hardware LEDC fade
This commit is contained in:
parent
33cb6f46bb
commit
a79b7569d1
|
|
@ -81,7 +81,7 @@ LedC::LedC(uint8_t pin, uint16_t freq, boolean invert){
|
|||
///////////////////
|
||||
|
||||
LedPin::LedPin(uint8_t pin, float level, uint16_t freq, boolean invert) : LedC(pin, freq, invert){
|
||||
|
||||
|
||||
if(!channel)
|
||||
Serial.printf("\n*** ERROR: Can't create LedPin(%d) - no open PWM channels and/or Timers ***\n\n",pin);
|
||||
else
|
||||
|
|
@ -95,8 +95,9 @@ LedPin::LedPin(uint8_t pin, float level, uint16_t freq, boolean invert) : LedC(p
|
|||
channel->flags.output_invert?"(inverted)":""
|
||||
);
|
||||
|
||||
set(level);
|
||||
|
||||
ledc_fade_func_install(0);
|
||||
|
||||
set(level);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
|
|
@ -110,9 +111,24 @@ void LedPin::set(float level){
|
|||
level=100;
|
||||
|
||||
float d=level*(pow(2,(int)timer->duty_resolution)-1)/100.0;
|
||||
|
||||
channel->duty=d;
|
||||
ledc_channel_config(channel);
|
||||
|
||||
ledc_channel_config(channel);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
|
|
|
|||
|
|
@ -77,6 +77,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
|
||||
|
||||
static void HSVtoRGB(float h, float s, float v, float *r, float *g, float *b ); // converts Hue/Saturation/Brightness to R/G/B
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,12 +28,7 @@
|
|||
// This is a placeholder .ino file that allows you to easily edit the contents of this files using the Arduino IDE,
|
||||
// as well as compile and test from this point. This file is ignored when the library is included in other sketches.
|
||||
|
||||
#include "Blinker.h"
|
||||
#include "Pixel.h"
|
||||
#include <Wire.h>
|
||||
|
||||
Blinker p(new Pixel(2),10);
|
||||
//Blinker p(NULL,10);
|
||||
#include "PwmPin.h"
|
||||
|
||||
void setup() {
|
||||
|
||||
|
|
@ -41,19 +36,16 @@ void setup() {
|
|||
Serial.flush();
|
||||
delay(1000); // wait for interface to flush
|
||||
|
||||
Serial.println("\n\nHomeSpan Blinker Example\n");
|
||||
Serial.printf("Pins = %d\n",p.getPin());
|
||||
Serial.println("\n\nHomeSpan LED Fade Test\n");
|
||||
|
||||
LedPin led(26,50);
|
||||
Serial.printf("Start\n");
|
||||
led.fade(0,10000);
|
||||
Serial.printf("End\n");
|
||||
|
||||
while(1);
|
||||
|
||||
p.on();
|
||||
delay(2000);
|
||||
p.off();
|
||||
delay(2000);
|
||||
p.start(300,0.25,4,1000);
|
||||
delay(5000);
|
||||
Serial.printf("New Pattern\n");
|
||||
p.start(200,0.2,2,200);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
p.check();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue