Skip to content

Commit

Permalink
setupMax function example
Browse files Browse the repository at this point in the history
  • Loading branch information
Koryphon committed Jul 25, 2018
1 parent 4958757 commit e5dde59
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions examples/setupMax/setupMax.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* A setupMax example for LightDimmer with the builtin LED.
*
* Blinking is started with the default values:
* - Brightening time equal to 250ms
* - Fading time equal to 250ms
* - On time equal to 200ms
* - Period equal to 900ms
*/

#include <LightDimmer.h>

LightDimmerSoft myLED;

void setup() {
Serial.begin(115200);
myLED.begin(13,HIGH);
myLED.startBlink();
}

uint8_t maxVal = 255;

uint8_t saturationAdd(const uint8_t val, const uint8_t add)
{
if ((255 - add) < val) return 255;
else return val + add;
}

uint8_t saturationSub(const uint8_t val, const uint8_t sub)
{
if (sub > val) return 0;
else return val - sub;
}

void loop() {
if (Serial.available()) {
char key = Serial.read();
switch (key) {
case 'p': maxVal = saturationAdd(maxVal, 10); myLED.setupMax(maxVal); break;
case 'o': maxVal = saturationSub(maxVal, 10); myLED.setupMax(maxVal); break;
case 'b': myLED.startBlink();
}
}
LightDimmer::update();
}
1 change: 1 addition & 0 deletions src/LightDimmer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void LightDimmer::begin(const uint8_t inPin, const uint8_t inOn)
void LightDimmer::setupMax(const uint8_t inMax)
{
mState = LD_ON;
mBlink = false;
mValue = mMax = inMax;
}

Expand Down

0 comments on commit e5dde59

Please sign in to comment.