From 61655845a9d31051a3426f415017d52ee6d49c6d Mon Sep 17 00:00:00 2001 From: Gregg Date: Fri, 19 Mar 2021 06:38:41 -0500 Subject: [PATCH] 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. --- src/extras/PwmPin.cpp | 3 ++- src/extras/PwmPin.h | 7 ++++--- src/extras/extras.ino | 29 ++++++++++++++++------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/extras/PwmPin.cpp b/src/extras/PwmPin.cpp index 6fb67cf..58c7fa6 100644 --- a/src/extras/PwmPin.cpp +++ b/src/extras/PwmPin.cpp @@ -20,10 +20,11 @@ PwmPin::PwmPin(uint8_t channel, uint8_t pin){ ledChannel.timer_sel=LEDC_TIMER_0; ledChannel.duty=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/=100; ledChannel.duty&=0x03FF; diff --git a/src/extras/PwmPin.h b/src/extras/PwmPin.h index 791fd7f..bb30eb7 100644 --- a/src/extras/PwmPin.h +++ b/src/extras/PwmPin.h @@ -16,9 +16,10 @@ class PwmPin { ledc_channel_config_t ledChannel; public: - 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) - int getPin(){return pin;} // returns the pin number + PwmPin(uint8_t channel, uint8_t pin); // assigns pin to be output of one of 16 PWM channels (0-15) + void set(uint8_t level); // sets the PWM duty to level (0-100) + 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 diff --git a/src/extras/extras.ino b/src/extras/extras.ino index d07e894..67c5120 100644 --- a/src/extras/extras.ino +++ b/src/extras/extras.ino @@ -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, // 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(){ @@ -11,20 +14,20 @@ void setup(){ Serial.print("\n\nTest sketch for HomeSpan Extras Library\n\n"); - RFControl rf(4); - 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(){ - + + 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); + } + }