Make LEDOutput responsible for inverting output
This commit is contained in:
parent
8c50498c7d
commit
0432071759
3 changed files with 10 additions and 6 deletions
|
@ -6,10 +6,12 @@
|
|||
|
||||
class LEDOutput {
|
||||
unsigned int _channel;
|
||||
bool _invert;
|
||||
|
||||
public:
|
||||
LEDOutput(unsigned int channel) {
|
||||
public:
|
||||
LEDOutput(unsigned int channel, bool invert = false) {
|
||||
_channel = channel;
|
||||
_invert = invert;
|
||||
ledcSetup(channel, LED_OUTPUT_FREQUENCY, LED_OUTPUT_RESOLUTION);
|
||||
}
|
||||
|
||||
|
@ -17,6 +19,9 @@ class LEDOutput {
|
|||
ledcAttachPin(pin, _channel);
|
||||
}
|
||||
void writeFraction(float fraction){
|
||||
ledcWrite(_channel, fraction * LED_OUTPUT_PWM_RANGE);
|
||||
auto value = fraction * LED_OUTPUT_PWM_RANGE;
|
||||
if (_invert)
|
||||
value = LED_OUTPUT_PWM_RANGE - value;
|
||||
ledcWrite(_channel, value);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue