12
12
The Sketch shows how to setup the library and bind a special function to the doubleclick event.
13
13
In the loop function the button.tick function has to be called as often as you like.
14
14
*/
15
-
15
+
16
16
// 03.03.2011 created by Matthias Hertel
17
17
// 01.12.2011 extension changed to work with the Arduino 1.0 environment
18
18
19
19
#include " OneButton.h"
20
20
21
- // Setup a new OneButton on pin A1.
22
- OneButton button (A1, true );
21
+ // Example for Arduino UNO with input button on A1
22
+ #define PIN_INPUT A1
23
+ #define PIN_LED 13
24
+
25
+ // Example for ESP8266 with input button on D5 and using the led on -12 module.
26
+ // #define PIN_INPUT D5
27
+ // #define PIN_LED D4
28
+
29
+ // Setup a new OneButton on pin PIN_INPUT
30
+
31
+ // The 2. parameter activeLOW is true, because external wiring sets the button to LOW when pressed.
32
+ OneButton button (PIN_INPUT, true );
33
+
34
+ // In case the momentary button puts the input to HIGH when pressed:
35
+ // The 2. parameter activeLOW is false when the external wiring sets the button to HIGH when pressed.
36
+ // The 3. parameter can be used to disable the PullUp .
37
+ // OneButton button(PIN_INPUT, false, false);
23
38
24
39
25
40
// setup code here, to run once:
26
- void setup () {
41
+ void setup ()
42
+ {
43
+ Serial.begin (115200 );
44
+
27
45
// enable the standard led on pin 13.
28
- pinMode (13 , OUTPUT); // sets the digital pin as output
29
-
30
- // link the doubleclick function to be called on a doubleclick event.
46
+ pinMode (PIN_LED , OUTPUT); // sets the digital pin as output
47
+
48
+ // link the doubleclick function to be called on a doubleclick event.
31
49
button.attachDoubleClick (doubleclick);
50
+
51
+
32
52
} // setup
33
-
34
53
35
- // main code here, to run repeatedly:
36
- void loop () {
54
+
55
+ // main code here, to run repeatedly:
56
+ void loop ()
57
+ {
37
58
// keep watching the push button:
38
59
button.tick ();
39
60
40
- // You can implement other code in here or just wait a while
61
+ // You can implement other code in here or just wait a while
41
62
delay (10 );
42
63
} // loop
43
64
44
65
45
66
// this function will be called when the button was pressed 2 times in a short timeframe.
46
- void doubleclick () {
67
+ void doubleclick ()
68
+ {
47
69
static int m = LOW;
48
- // reverse the LED
70
+ // reverse the LED
49
71
m = !m;
50
- digitalWrite (13 , m);
72
+ digitalWrite (PIN_LED , m);
51
73
} // doubleclick
52
74
53
75
// End
0 commit comments