From 3977090becfb812ec4560a8f676b2ea9f36f06d6 Mon Sep 17 00:00:00 2001 From: Tomas Pilny Date: Thu, 27 Apr 2023 12:50:38 +0200 Subject: [PATCH 1/2] Added link to external examples to the doc --- docs/source/getting_started.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 0b4280d4b91..4093b415c07 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -133,6 +133,7 @@ in the examples menu or inside each library folder. https://github.com/espressif/arduino-esp32/tree/master/libraries +There is also a `list of examples `_ managed outside of Espressif, so check them out. .. include:: common/datasheet.inc From 205fbecadc50a796336db143ac2ba71c9a0aab9b Mon Sep 17 00:00:00 2001 From: Tomas Pilny Date: Tue, 9 May 2023 13:14:27 +0200 Subject: [PATCH 2/2] Fixed FunctionalInterrupt.ino + added introduction comment and few outputs --- .../FunctionalInterrupt.ino | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino b/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino index 844a14dabd1..d028f4ea036 100644 --- a/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino +++ b/libraries/ESP32/examples/GPIO/FunctionalInterrupt/FunctionalInterrupt.ino @@ -1,26 +1,45 @@ +/* + * This example demonstrates usage of interrupt by detecting a button press. + * + * Setup: Connect first button between pin defined in BUTTON1 and GND + * Similarly connect second button between pin defined in BUTTON2 and GND. + * If you do not have a button simply connect a wire to those buttons + * - touching GND pin with other end of the wire will behave same as pressing the connected button. + * Wen using the bare wire be careful not to touch any other pin by accident. + * + * Note: There is no de-bounce implemented and the physical connection will normally + * trigger many more button presses than actually happened. + * This is completely normal and is not to be considered a fault. + */ + + #include #include #define BUTTON1 16 #define BUTTON2 17 -class Button -{ +class Button{ public: Button(uint8_t reqPin) : PIN(reqPin){ pinMode(PIN, INPUT_PULLUP); - attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING); }; - ~Button() { + + void begin(){ + attachInterrupt(PIN, std::bind(&Button::isr,this), FALLING); + Serial.printf("Started button interrupt on pin %d\n", PIN); + } + + ~Button(){ detachInterrupt(PIN); } - void ARDUINO_ISR_ATTR isr() { + void ARDUINO_ISR_ATTR isr(){ numberKeyPresses += 1; pressed = true; } - void checkPressed() { + void checkPressed(){ if (pressed) { Serial.printf("Button on pin %u has been pressed %u times\n", PIN, numberKeyPresses); pressed = false; @@ -28,7 +47,7 @@ public: } private: - const uint8_t PIN; + const uint8_t PIN; volatile uint32_t numberKeyPresses; volatile bool pressed; }; @@ -36,9 +55,13 @@ private: Button button1(BUTTON1); Button button2(BUTTON2); - void setup() { Serial.begin(115200); + while(!Serial) delay(10); + Serial.println("Starting Functional Interrupt example."); + button1.begin(); + button2.begin(); + Serial.println("Setup done."); } void loop() {