Lesson02: BOOT Button Serial Output¶
1. Learning Objectives¶
In this lesson, you will learn how to read the onboard BOOT button and print press, single-click, double-click, and long-press events through the serial port. Power and Reset button events are not printed in this lesson: the Reset button resets the program; a single click of the Power button turns the display on or off, while a long press shuts down the device. The encoder button will be covered in the encoder lesson.
2. Prerequisites¶
- Completed the ESP32-S3 environment setup in Lesson01.
- Additional library:
OneButton. This project uses version2.6.1.
How to add the library files:
- OneButton: 2.6.1
- Library download link:https://github.com/Elecrow-RD/CrowPanel_2.01_inch-HMI_ESP32_Watch_Display_240_296/tree/master/example/V1.0/Arduino/Lesson02_Boot_Button
3. Arduino IDE Instructions¶
-
Confirm that the board, Flash, PSRAM, and partition scheme settings are exactly the same as in Lesson01.

-
Confirm that the
OneButtonlibrary is installed or that the sharedlibrariesfolder exists.
-
Select the actual serial port and click Verify to compile. (Connect the hardware using a USB data cable.)

-
Click Upload to flash the program, then open Serial Monitor and set the baud rate to
115200.
-
Press the BOOT button and observe the event messages in the serial output.

4. Hardware Instructions¶
- Connect the development board to the computer using a USB data cable, and keep Serial Monitor open.
- Briefly press the BOOT button and check whether the BOOT button event is printed in the serial output.
-
Quickly press the BOOT button twice in succession and observe the double-click event.
-
Press and hold the BOOT button for approximately 1 second or longer, and observe the long-press start and long-press end events.
-
Do not operate the Reset or Power buttons in this lesson. Reset resets the program; a single click of Power turns the display on or off, while a long press shuts down the device.
5. Key Code Explanation¶
kBootButtonPin refers to GPIO0, which is connected to the BOOT button on the ESP32-S3 module. In the OneButton constructor, the first true indicates that the button is active-low, and the second true enables the internal pull-up resistor. As a result, the input is HIGH when the button is not pressed and is pulled LOW when the button is pressed.
Mechanical buttons produce contact bounce, so setDebounceMs(30) filters out glitches shorter than 30 ms. setClickMs(400) defines the detection window for single and double clicks, while setPressMs(1000) defines the long-press threshold. Together, these three timing settings determine how button events are recognized.
bootButton.attachPress(onBootPressed);
bootButton.attachClick(onBootClicked);
bootButton.attachDoubleClick(onBootDoubleClicked);
bootButton.attachLongPressStart(onBootLongPressStarted);
bootButton.attachLongPressStop(onBootLongPressStopped);
This code binds different button events to different callback functions. After the student presses the BOOT button, OneButton automatically determines the event type based on timing and state, then calls the corresponding function to print information to the serial output.
OneButton is not driven by hardware interrupts, so it must be called frequently in loop(). Each call to tick() reads the button state once and updates the event state machine. delay(5) keeps the loop’s sampling frequency sufficiently high while preventing the CPU from busy-waiting.



