Make LEDOutput responsible for inverting output
This commit is contained in:
parent
8c50498c7d
commit
0432071759
3 changed files with 10 additions and 6 deletions
|
@ -54,7 +54,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
float multiplier = getOutputMultiplier();
|
_output->writeFraction(getOutputMultiplier());
|
||||||
_output->writeFraction(1 - multiplier);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
|
|
||||||
class LEDOutput {
|
class LEDOutput {
|
||||||
unsigned int _channel;
|
unsigned int _channel;
|
||||||
|
bool _invert;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LEDOutput(unsigned int channel) {
|
LEDOutput(unsigned int channel, bool invert = false) {
|
||||||
_channel = channel;
|
_channel = channel;
|
||||||
|
_invert = invert;
|
||||||
ledcSetup(channel, LED_OUTPUT_FREQUENCY, LED_OUTPUT_RESOLUTION);
|
ledcSetup(channel, LED_OUTPUT_FREQUENCY, LED_OUTPUT_RESOLUTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +19,9 @@ class LEDOutput {
|
||||||
ledcAttachPin(pin, _channel);
|
ledcAttachPin(pin, _channel);
|
||||||
}
|
}
|
||||||
void writeFraction(float fraction){
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,7 +32,7 @@ class BluetoothCallback : public BLECharacteristicCallbacks {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LEDOutput _ledOutput(0);
|
LEDOutput _ledOutput(0, true);
|
||||||
LED _led(&_ledOutput, FADE_IN_DURATION, FADE_OUT_DURATION);
|
LED _led(&_ledOutput, FADE_IN_DURATION, FADE_OUT_DURATION);
|
||||||
|
|
||||||
void toggle(){
|
void toggle(){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue