A small and simple Arduino library to handle physical buttons using internal pull-up resistors, making wiring and reading easier.
- Easy-to-use, minimal interface.
- Automatically uses
INPUT_PULLUP(no need for external resistors). isPressed()method to check button state.- Great for projects with multiple buttons.
- Download the repository as a ZIP file or clone it to your Arduino libraries folder
git clone https://github.com/hanzeelvilla/MyButtonIO.git- Place the MyButtonIO folder into your Arduino libraries directory (typically Documents/Arduino/libraries on most systems).
- Restart the Arduino IDE if it was open during installation.
To use the library in your Arduino sketch, include the MyButtonIO.h header file.
#include "MyButtonIO.h"Create a MyButtonIO object by passing the GPIO pin number where your button is connected
MyButtonIO myBtn(12); // Button connected to pin 12Before checking the button state, initialize it in the setup() function. This sets the pin mode to INPUT_PULLUP automatically
void setup() {
myBtn.init();
}Use the isPressed() method inside the loop() to check if the button is being pressed. It returns true when the button is pressed (LOW)
void loop() {
if (myBtn.isPressed()) {
Serial.println("Button Pressed!");
}
}| Method | Description |
|---|---|
init() |
Initializes the button pin as INPUT_PULLUP |
isPressed() |
Returns true if the button is pressed |
Warning
Ensure the relay is connected properly to avoid short circuits or damage to the board.