Skip to content

Commit e5dde59

Browse files
committed
setupMax function example
1 parent 4958757 commit e5dde59

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

examples/setupMax/setupMax.ino

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* A setupMax example for LightDimmer with the builtin LED.
3+
*
4+
* Blinking is started with the default values:
5+
* - Brightening time equal to 250ms
6+
* - Fading time equal to 250ms
7+
* - On time equal to 200ms
8+
* - Period equal to 900ms
9+
*/
10+
11+
#include <LightDimmer.h>
12+
13+
LightDimmerSoft myLED;
14+
15+
void setup() {
16+
Serial.begin(115200);
17+
myLED.begin(13,HIGH);
18+
myLED.startBlink();
19+
}
20+
21+
uint8_t maxVal = 255;
22+
23+
uint8_t saturationAdd(const uint8_t val, const uint8_t add)
24+
{
25+
if ((255 - add) < val) return 255;
26+
else return val + add;
27+
}
28+
29+
uint8_t saturationSub(const uint8_t val, const uint8_t sub)
30+
{
31+
if (sub > val) return 0;
32+
else return val - sub;
33+
}
34+
35+
void loop() {
36+
if (Serial.available()) {
37+
char key = Serial.read();
38+
switch (key) {
39+
case 'p': maxVal = saturationAdd(maxVal, 10); myLED.setupMax(maxVal); break;
40+
case 'o': maxVal = saturationSub(maxVal, 10); myLED.setupMax(maxVal); break;
41+
case 'b': myLED.startBlink();
42+
}
43+
}
44+
LightDimmer::update();
45+
}

src/LightDimmer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void LightDimmer::begin(const uint8_t inPin, const uint8_t inOn)
5050
void LightDimmer::setupMax(const uint8_t inMax)
5151
{
5252
mState = LD_ON;
53+
mBlink = false;
5354
mValue = mMax = inMax;
5455
}
5556

0 commit comments

Comments
 (0)