2.Button
This examples shows how to use the debounced Button class to toggle an LED.
- Boards: 🛈
- AVR, AVR USB, Nano Every, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Due, Teensy 3.x, ESP8266, ESP32
Connections
- 2: Momentary push button (other pin to ground)
The internal pull-up resistor will be enabled.
Behavior
- If you press the push button once, the built-in LED is turned on.
- If you press the button again, the LED is turned off again.
Written by PieterP, 2019-11-22
https://github.com/tttapa/Arduino-Helpers
Button pushbutton {2};
const pin_t ledPin = LED_BUILTIN;
void setup() {
pushbutton.begin();
}
void loop() {
static bool ledState =
LOW;
if (pushbutton.update() == Button::Falling) {
ledState = !ledState;
}
}
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
Dummy header file for Arduino builder.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.