File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
examples/Button2Integration Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Integration with https://github.com/LennartHennigs/Button2
2
+
3
+ #include " Modulino.h"
4
+ #include " Button2.h"
5
+
6
+ Button2 button;
7
+ ModulinoButtons modulino_buttons;
8
+
9
+ uint8_t button0StateHandler () {
10
+ modulino_buttons.update ();
11
+ return modulino_buttons.isPressed (0 ) ? LOW : HIGH; // fake a normal button -> LOW = pressed
12
+ }
13
+
14
+ void handler (Button2& btn) {
15
+ switch (btn.getType ()) {
16
+ case single_click:
17
+ break ;
18
+ case double_click:
19
+ Serial.print (" double " );
20
+ break ;
21
+ case triple_click:
22
+ Serial.print (" triple " );
23
+ break ;
24
+ case long_click:
25
+ Serial.print (" long" );
26
+ break ;
27
+ }
28
+ Serial.print (" click" );
29
+ Serial.print (" (" );
30
+ Serial.print (btn.getNumberOfClicks ());
31
+ Serial.println (" )" );
32
+ }
33
+
34
+ void setup () {
35
+
36
+ Serial.begin (115200 );
37
+
38
+ Modulino.begin ();
39
+ modulino_buttons.begin ();
40
+
41
+ button.setDebounceTime (35 );
42
+ button.setButtonStateFunction (button0StateHandler);
43
+ button.setClickHandler (handler);
44
+ button.setDoubleClickHandler (handler);
45
+ button.setTripleClickHandler (handler);
46
+ button.setLongClickHandler (handler);
47
+ button.begin (BTN_VIRTUAL_PIN);
48
+ }
49
+
50
+ void loop () {
51
+ button.loop ();
52
+ }
You can’t perform that action at this time.
0 commit comments