11# ArduinoButton
22
3- Library for facilitating interfacing with buttons.
3+ The ** ArduinoButton ** library simplifies interfacing with buttons on Arduino .
44
55## Installation
66
771 . Download the latest zip file from the [ releases] ( https://github.com/JMax45/arduino-button/releases ) page.
8- 2 . Install the zip file via Sketch-> #include-> Add library from .ZIP file.
8+ 2 . Install the zip file via Sketch -> #include -> Add library from .ZIP file.
99
1010## Usage
1111
@@ -14,33 +14,55 @@ Library for facilitating interfacing with buttons.
1414
1515#define BUTTON_PIN 7
1616
17- ArduinoButton button (BUTTON_PIN);
17+ ArduinoButton button (BUTTON_PIN, false); // Set to true for active-low, false for active-high
1818
1919void setup() {
2020 Serial.begin(9600);
2121
22- // Callback for key up event
22+ // Callback for button release event
2323 button.onKeyUp([ ] ( ) {
24- Serial.print("button click callback");
24+ Serial.print("Button click callback");
2525 });
2626
27- // Callback for key down event
27+ // Callback for button press event
2828 button.onKeyDown([ ] ( ) {
29- Serial.print("button down callback");
29+ Serial.print("Button down callback");
3030 });
3131
3232 // Callback for double click event
3333 button.onDoubleClick([ ] ( ) {
34- Serial.print("double click callback");
34+ Serial.print("Double click callback");
3535 });
3636
3737 // Callback for double click with a custom delay between two clicks (e.g., 1000ms)
3838 button.onDoubleClick([ ] ( ) {
39- Serial.print("double click callback with custom delay");
39+ Serial.print("Double click callback with custom delay");
4040 }, 1000);
4141}
4242
4343void loop() {
4444 button.loop();
4545}
4646```
47+
48+ **Note**: The second parameter in `ArduinoButton button(BUTTON_PIN, false);` indicates whether the button is active-low (true) or active-high (false).
49+
50+ ## Active-Low vs. Active-High Buttons
51+
52+ Buttons can be configured in two ways: active-low or active-high. Understanding the difference is important.
53+
54+ ### Active-Low
55+
56+ - In an active-low configuration, the button is considered "pressed" or "active" when its input is pulled low, typically to GND (Ground).
57+ - When the button is not pressed, its input is held high (typically at VCC or the power supply voltage).
58+ - Active-low buttons are commonly used because they are often more straightforward to wire and interface.
59+
60+ ### Active-High
61+
62+ - In an active-high configuration, the button is considered "pressed" or "active" when its input is connected to the power supply voltage (VCC).
63+ - When the button is not pressed, its input is pulled low, typically to GND (Ground).
64+ - Active-high buttons can be useful in certain scenarios.
65+
66+ 
67+
68+ Ensure that you connect the button and the library accordingly based on your chosen configuration (active-low or active-high). The library handles the specifics of button state detection, regardless of the configuration chosen.
0 commit comments