Skip to content

Commit b8378fb

Browse files
committed
example with better doku inline
1 parent a05a69e commit b8378fb

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

examples/SimpleOneButton/SimpleOneButton.ino

+36-14
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,64 @@
1212
The Sketch shows how to setup the library and bind a special function to the doubleclick event.
1313
In the loop function the button.tick function has to be called as often as you like.
1414
*/
15-
15+
1616
// 03.03.2011 created by Matthias Hertel
1717
// 01.12.2011 extension changed to work with the Arduino 1.0 environment
1818

1919
#include "OneButton.h"
2020

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);
2338

2439

2540
// setup code here, to run once:
26-
void setup() {
41+
void setup()
42+
{
43+
Serial.begin(115200);
44+
2745
// 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.
3149
button.attachDoubleClick(doubleclick);
50+
51+
3252
} // setup
33-
3453

35-
// main code here, to run repeatedly:
36-
void loop() {
54+
55+
// main code here, to run repeatedly:
56+
void loop()
57+
{
3758
// keep watching the push button:
3859
button.tick();
3960

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
4162
delay(10);
4263
} // loop
4364

4465

4566
// this function will be called when the button was pressed 2 times in a short timeframe.
46-
void doubleclick() {
67+
void doubleclick()
68+
{
4769
static int m = LOW;
48-
// reverse the LED
70+
// reverse the LED
4971
m = !m;
50-
digitalWrite(13, m);
72+
digitalWrite(PIN_LED, m);
5173
} // doubleclick
5274

5375
// End

0 commit comments

Comments
 (0)