Move components to lib folder
This commit is contained in:
parent
ae3c20b59d
commit
b9b68f08cb
8 changed files with 1 additions and 0 deletions
33
lib/LED/LEDOutput.cpp
Normal file
33
lib/LED/LEDOutput.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef LEDOutput_cpp
|
||||
#define LEDOutput_cpp
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define LED_OUTPUT_FREQUENCY 490
|
||||
#define LED_OUTPUT_RESOLUTION 15
|
||||
#define LED_OUTPUT_PWM_RANGE 32767
|
||||
|
||||
class LEDOutput {
|
||||
unsigned int _channel;
|
||||
bool _invert;
|
||||
|
||||
public:
|
||||
LEDOutput(unsigned int channel, bool invert = false) {
|
||||
_channel = channel;
|
||||
_invert = invert;
|
||||
ledcSetup(channel, LED_OUTPUT_FREQUENCY, LED_OUTPUT_RESOLUTION);
|
||||
}
|
||||
|
||||
void attach(unsigned int pin){
|
||||
ledcAttachPin(pin, _channel);
|
||||
}
|
||||
|
||||
void writeFraction(float fraction){
|
||||
auto value = fraction * LED_OUTPUT_PWM_RANGE;
|
||||
if (_invert)
|
||||
value = LED_OUTPUT_PWM_RANGE - value;
|
||||
ledcWrite(_channel, value);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue