Skip to content

Add getPin() function and the ability to force analogWrite. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/ezLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ezLED::ezLED(int pin, int mode) {
_ledState = LED_STATE_IDLE;
_outputState = LED_OFF; // LED_OFF, LED_ON
_brightness = 0; // 0 to 255
_forceAnalog = false;

_fadeFrom = 0;
_fadeTo = 0;
Expand All @@ -54,6 +55,10 @@ ezLED::ezLED(int pin, int mode) {
pinMode(_ledPin, OUTPUT);
}

void ezLED::useAnalog(bool forceAnalog) {
_forceAnalog = forceAnalog;
}

void ezLED::setBlink(unsigned long onTime, unsigned long offTime, unsigned long delayTime) {
_blinkOnTime = onTime;
_blinkOffTime = offTime;
Expand All @@ -75,7 +80,12 @@ void ezLED::updateDigital() {
else
state = (_outputState == LED_OFF) ? HIGH : LOW;

digitalWrite(_ledPin, state);
if (_forceAnalog == true) {
_brightness = state == HIGH ? 255 : 0;
updateAnalog();
} else {
digitalWrite(_ledPin, state);
}
}

void ezLED::turnON(unsigned long delayTime) {
Expand Down Expand Up @@ -220,6 +230,10 @@ int ezLED::getState(void) {
}
}

int ezLED::getPin(void) {
return _ledPin;
}

void ezLED::loop(void) {

switch(_ledState) {
Expand Down
3 changes: 3 additions & 0 deletions src/ezLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ezLED
unsigned char _ledState;
unsigned char _outputState; // LED_OFF, LED_ON
int _brightness; // 0 to 255
bool _forceAnalog = false;

unsigned char _fadeFrom = 0;
unsigned char _fadeTo = 0;
Expand All @@ -87,6 +88,7 @@ class ezLED

public:
ezLED(int pin, int mode = CTRL_ANODE);
void useAnalog(bool forceAnalog);
void turnON(unsigned long delayTime = 0);
void turnOFF(unsigned long delayTime = 0);
void toggle(unsigned long delayTime = 0);
Expand All @@ -101,6 +103,7 @@ class ezLED

int getOnOff(void);
int getState(void);
int getPin(void);
void loop(void);
};

Expand Down