Skip to content

Commit

Permalink
Arduino Nano ESP32 compatible setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mathertel committed Jul 31, 2024
1 parent 05242ac commit 93ca0ae
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions examples/SimpleOneButton/SimpleOneButton.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
#define PIN_INPUT D3
#define PIN_LED D4

#elif defined(ESP32) && defined(ARDUINO_NANO_ESP32)
// For Arduino Nano ESP32 use D3 for button
#define PIN_INPUT D3
// For Arduino Nano ESP32 use e.g. LED_RED
#define PIN_LED LED_RED

#elif defined(ESP32)
// Example pin assignments for a ESP32 board
// Some boards have a BOOT switch using GPIO 0.
Expand All @@ -40,7 +46,7 @@

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

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

// enable the standard led on pin 13.
// enable the standard led on pin PIN_LED.
pinMode(PIN_LED, OUTPUT); // sets the digital pin as output

// enable the standard led on pin 13.
digitalWrite(PIN_LED, ledState);

// setup OneButton
button = new OneButton(PIN_INPUT, true);

// link the doubleclick function to be called on a doubleclick event.
button.attachDoubleClick(doubleClick);
button->attachDoubleClick(doubleClick);
} // setup


// main code here, to run repeatedly:
void loop()
{
// keep watching the push button:
button.tick();
button->tick();

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

0 comments on commit 93ca0ae

Please sign in to comment.