Updated PWM

Removed need to include channel number in set() method.  Why was this ever there?  Need to update Examples and PwmPin docs.  But keep stub method that includes channel for backwards compatibility.
This commit is contained in:
Gregg 2021-03-19 06:38:41 -05:00
parent 6aba1a28e5
commit 61655845a9
3 changed files with 22 additions and 17 deletions

View File

@ -20,10 +20,11 @@ PwmPin::PwmPin(uint8_t channel, uint8_t pin){
ledChannel.timer_sel=LEDC_TIMER_0; ledChannel.timer_sel=LEDC_TIMER_0;
ledChannel.duty=0; ledChannel.duty=0;
ledChannel.hpoint=0; ledChannel.hpoint=0;
ledc_channel_config(&ledChannel);
} }
void PwmPin::set(uint8_t channel, uint8_t level){ void PwmPin::set(uint8_t level){
ledChannel.duty=level*1023; ledChannel.duty=level*1023;
ledChannel.duty/=100; ledChannel.duty/=100;
ledChannel.duty&=0x03FF; ledChannel.duty&=0x03FF;

View File

@ -16,9 +16,10 @@ class PwmPin {
ledc_channel_config_t ledChannel; ledc_channel_config_t ledChannel;
public: public:
PwmPin(uint8_t channel, uint8_t pin); // assigns pin to be output of one of 16 PWM channels (0-15) PwmPin(uint8_t channel, uint8_t pin); // assigns pin to be output of one of 16 PWM channels (0-15)
void set(uint8_t channel, uint8_t level); // sets the PWM duty of channel to level (0-100) void set(uint8_t level); // sets the PWM duty to level (0-100)
int getPin(){return pin;} // returns the pin number void set(uint8_t channel, uint8_t level){set(level);} // sets the PWM duty to level (0-100) - deprecated, but defined for backwards compatibility
int getPin(){return pin;} // returns the pin number
static void HSVtoRGB(float h, float s, float v, float *r, float *g, float *b ); // converts Hue/Saturation/Brightness to R/G/B static void HSVtoRGB(float h, float s, float v, float *r, float *g, float *b ); // converts Hue/Saturation/Brightness to R/G/B

View File

@ -2,7 +2,10 @@
// This is a placeholder .ino file that allows you to easily edit the contents of this library using the Arduino IDE, // This is a placeholder .ino file that allows you to easily edit the contents of this library 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. // as well as compile and test from this point. This file is ignored when the library is included in other sketches.
#include "RFControl.h" #include "PwmPin.h"
PwmPin yellow(0,16);
PwmPin red(1,17);
void setup(){ void setup(){
@ -11,20 +14,20 @@ void setup(){
Serial.print("\n\nTest sketch for HomeSpan Extras Library\n\n"); Serial.print("\n\nTest sketch for HomeSpan Extras Library\n\n");
RFControl rf(4);
Serial.println("Starting..."); Serial.println("Starting...");
rf.clear();
for(int i=0;i<3;i++)
rf.add(2000,2000);
rf.phase(10000,0);
rf.start(5,100);
Serial.println("Done!");
} }
void loop(){ void loop(){
for(int i=0;i<100;i++){
red.set(22,i);
delay(10);
}
for(int i=100;i>=0;i--){
yellow.set(i);
delay(10);
}
} }