Control Surface  1.1.1
MIDI Control Surface library for Arduino
2.Button.ino

2.Button

This examples shows how to use the debounced Button class to toggle an LED.

Boards:
AVR, AVR USB, Nano 33, Due, Teensy 3.x, ESP8266, ESP32

Connections

The internal pull-up resistor will be enabled.

Behavior

Written by PieterP, 2019-11-22
https://github.com/tttapa/Arduino-Helpers

// Include the library
// Create a Button object that reads a push button connected to pin 2:
Button pushbutton = {2};
// The pin with the LED connected:
const pin_t ledPin = LED_BUILTIN;
void setup() {
pinMode(ledPin, OUTPUT);
pushbutton.begin();
// You can invert the input, for use with normally closed (NC) switches:
// pushbutton.invert();
}
void loop() {
static bool ledState = LOW;
// Read the digital input, debounce the signal, and check the state of
// the button:
if (pushbutton.update() == Button::Falling) {
ledState = !ledState; // Invert the state of the LED
digitalWrite(ledPin, ledState); // Update the LED with the new state
}
}
AH::ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:36
Button.hpp
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:47
Arduino_Helpers.h
Dummy header file for Arduino builder. You have to add this file first, so the other headers are in t...
OUTPUT
const uint8_t OUTPUT
Definition: ExtendedInputOutput.hpp:50
AH::ExtIO::digitalWrite
void digitalWrite(pin_t pin, uint8_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:48