Skip to content

Commit 9c4e0ae

Browse files
committed
Blink Machine doku added
1 parent 59cf77c commit 9c4e0ae

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

examples/BlinkMachine/BlinkMachine.ino

+32-9
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,52 @@
1919
A click on the button turns the led on.
2020
A doubleclick on the button changes the blink rate from ON to SLOW to FAST and back.
2121
In the loop function the button.tick function has to be called as often as you like.
22+
23+
State-Diagram
24+
25+
start
26+
| +-------\
27+
V V |
28+
-------- ------ |
29+
| OFF |<--click-+->| ON | |
30+
-------- | ------ |
31+
| | |
32+
| d-click |
33+
| | |
34+
| V |
35+
| ------ |
36+
+- | SLOW | |
37+
| ------ |
38+
| | |
39+
| d-click |
40+
| | |
41+
| V d-click
42+
| ------ |
43+
+--| FAST |---/
44+
------
2245
*/
2346

2447
// 06.10.2012 created by Matthias Hertel
48+
// 26.03.2017 state diagram added, minor changes
2549

2650
#include "OneButton.h"
2751

2852
// The actions I ca do...
2953
typedef enum {
30-
ACTION_NONE, // do nothing.
54+
ACTION_OFF, // set LED "OFF".
3155
ACTION_ON, // set LED "ON"
3256
ACTION_SLOW, // blink LED "SLOW"
33-
ACTION_FAST // blink LED "FAST"
57+
ACTION_FAST // blink LED "FAST"
3458
}
3559
MyActions;
3660

3761
// Setup a new OneButton on pin A1.
3862
OneButton button(A1, true);
3963

40-
MyActions nextAction = ACTION_NONE; // no action when starting
64+
MyActions nextAction = ACTION_OFF; // no action when starting
65+
4166

42-
// setup code here, to run once:
67+
// setup code here, to run once.
4368
void setup() {
4469
// enable the standard led on pin 13.
4570
pinMode(13, OUTPUT); // sets the digital pin as output
@@ -61,7 +86,7 @@ void loop() {
6186

6287
// You can implement other code in here or just wait a while
6388

64-
if (nextAction == ACTION_NONE) {
89+
if (nextAction == ACTION_OFF) {
6590
// do nothing.
6691
digitalWrite(13, LOW);
6792

@@ -84,18 +109,16 @@ void loop() {
84109
} else {
85110
digitalWrite(13, HIGH);
86111
} // if
87-
88112
} // if
89-
90113
} // loop
91114

92115

93116
// this function will be called when the button was pressed 1 time and them some time has passed.
94117
void myClickFunction() {
95-
if (nextAction == ACTION_NONE)
118+
if (nextAction == ACTION_OFF)
96119
nextAction = ACTION_ON;
97120
else
98-
nextAction = ACTION_NONE;
121+
nextAction = ACTION_OFF;
99122
} // myClickFunction
100123

101124

0 commit comments

Comments
 (0)