Skip to content

Commit

Permalink
version 1.3. Added a max value for the duty cycle so the maximum brig…
Browse files Browse the repository at this point in the history
…htness of each LED can be set.
  • Loading branch information
Koryphon committed Apr 5, 2018
1 parent 47988ca commit 046f4e6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ In ```setup```, you shall call ```begin``` to start each LightDimmer and LightDi

In ```loop```, you shall call ```LightDimmer::update()``` to call the library so that it update the state of each declared object.

### Limitations

Period, on, brightening and fading times are 16 bits integer. So the maximum values of the time settings are 65,535s.

## Functions of LightDimmer

The following functions are available:

### LightDimmer::update()
Expand Down
17 changes: 9 additions & 8 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
+---------------------------------------------------------------------------+
| LightDimmer changelog |
+---------------------------------------------------------------------------+
1.2.3 fix forgotten implementation of setOnTime and setPeriod. Moved short
1.3 Added a maximum value to be able to set the brightness of each LED.
1.2.3 Fix forgotten implementation of setOnTime and setPeriod. Moved short
implementation to the header.
1.2.2 fix compilation problem with static used in static method
implementation
1.2.1 Out of beta
1.2 New example, updated documentation
1.1 added soft PWM. pin and level settings have been moved to begin() to
allow array of objects creation. Still in beta
1.0 initial beta release
1.2.2 Fix compilation problem with static used in static method
implementation.
1.2.1 Out of beta.
1.2 New example, updated documentation.
1.1 Added soft PWM. pin and level settings have been moved to begin() to
allow array of objects creation. Still in beta.
1.0 Initial beta release.
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LightDimmerSoft KEYWORD1
#######################################

setPeriod KEYWORD2
setMax KEYWORD2
setOnTime KEYWORD2
setFadingTime KEYWORD2
setBrighteningTime KEYWORD2
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=LightDimmer
version=1.2.3
version=1.3
author=Jean-Luc - Locoduino
maintainer=Jean-Luc - Locoduino
sentence=This library allows to drive a LED to simulate railroad signals.
paragraph=LightDimmer allows to drive a LED to simulate railroad signals. The user can specify a flashing period, a fade time and a rise time
sentence=This library allows to drive LEDs to simulate railroad signals.
paragraph=LightDimmer allows to drive LEDs to simulate railroad signals. The user can specify a flashing period, a fade time and a rise time for each LED. In addition the duty cycle corresponding to the on state can be specified.
category=Device Control
includes=LightDimmer.h
url=https://github.com/Locoduino/LightDimmer
Expand Down
9 changes: 5 additions & 4 deletions src/LightDimmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ LightDimmer *LightDimmer::sLightList = NULL;

LightDimmer::LightDimmer()
: mState(LD_OFF),
mMax(255),
mRiseTime(250),
mFallTime(250),
mOnTime(200),
Expand Down Expand Up @@ -100,11 +101,11 @@ void LightDimmer::updateState()
break;
case LD_RISING:
if (currentDate < mNextEventDate) {
uint8_t value = 255 * (currentDate - (mNextEventDate - mRiseTime)) / mRiseTime;
uint8_t value = mMax * (currentDate - (mNextEventDate - mRiseTime)) / mRiseTime;
mValue = mOff ? 255 - value : value;
}
else {
mValue = mOff ? 0 : 255 ;
mValue = mOff ? 255 - mMax : mMax ;
mNextEventDate = currentDate + mPeriod - mOnTime - mRiseTime -mFallTime;
mState = LD_ON;
}
Expand All @@ -119,8 +120,8 @@ void LightDimmer::updateState()
break;
case LD_FALLING:
if (currentDate < mNextEventDate) {
uint8_t value = 255 * (currentDate - (mNextEventDate - mFallTime)) / mFallTime;
mValue = mOff ? value : 255 - value;
uint8_t value = mMax * (currentDate - (mNextEventDate - mFallTime)) / mFallTime;
mValue = mOff ? value + 255 - mMax : mMax - value;
}
else {
mValue = mOff ? 255 : 0;
Expand Down
2 changes: 2 additions & 0 deletions src/LightDimmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LightDimmer
enum { LD_OFF, LD_ON, LD_RISING, LD_FALLING };

uint8_t mState;
uint8_t mMax;
uint16_t mRiseTime;
uint16_t mFallTime;
uint16_t mOnTime;
Expand All @@ -48,6 +49,7 @@ class LightDimmer
public:
LightDimmer();
void begin(const uint8_t inPin, const uint8_t inOn);
void setMax(const uint8_t inMax) { mMax = inMax; };
void setFadingTime(const uint16_t inFallTime) { mFallTime = inFallTime; };
void setBrighteningTime(const uint16_t inRiseTime) { mRiseTime = inRiseTime; };
void setOnTime(const uint16_t inOnTime) { mOnTime = inOnTime; };
Expand Down

0 comments on commit 046f4e6

Please sign in to comment.