Skip to content

Commit 93ca0ae

Browse files
committed
Arduino Nano ESP32 compatible setup
1 parent 05242ac commit 93ca0ae

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

examples/SimpleOneButton/SimpleOneButton.ino

+13-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
#define PIN_INPUT D3
3030
#define PIN_LED D4
3131

32+
#elif defined(ESP32) && defined(ARDUINO_NANO_ESP32)
33+
// For Arduino Nano ESP32 use D3 for button
34+
#define PIN_INPUT D3
35+
// For Arduino Nano ESP32 use e.g. LED_RED
36+
#define PIN_LED LED_RED
37+
3238
#elif defined(ESP32)
3339
// Example pin assignments for a ESP32 board
3440
// Some boards have a BOOT switch using GPIO 0.
@@ -40,7 +46,7 @@
4046

4147
// Setup a new OneButton on pin PIN_INPUT
4248
// The 2. parameter activeLOW is true, because external wiring sets the button to LOW when pressed.
43-
OneButton button(PIN_INPUT, true);
49+
OneButton *button;
4450

4551
// In case the momentary button puts the input to HIGH when pressed:
4652
// The 2. parameter activeLOW is false when the external wiring sets the button to HIGH when pressed.
@@ -56,22 +62,23 @@ void setup()
5662
Serial.begin(115200);
5763
Serial.println("One Button Example with polling.");
5864

59-
// enable the standard led on pin 13.
65+
// enable the standard led on pin PIN_LED.
6066
pinMode(PIN_LED, OUTPUT); // sets the digital pin as output
61-
62-
// enable the standard led on pin 13.
6367
digitalWrite(PIN_LED, ledState);
6468

69+
// setup OneButton
70+
button = new OneButton(PIN_INPUT, true);
71+
6572
// link the doubleclick function to be called on a doubleclick event.
66-
button.attachDoubleClick(doubleClick);
73+
button->attachDoubleClick(doubleClick);
6774
} // setup
6875

6976

7077
// main code here, to run repeatedly:
7178
void loop()
7279
{
7380
// keep watching the push button:
74-
button.tick();
81+
button->tick();
7582

7683
// You can implement other code in here or just wait a while
7784
delay(10);

0 commit comments

Comments
 (0)