Blink-Frequency-Buttons
This examples shows how to use two push buttons to set the frequency at which an LED blinks.
- 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)
- 3: Momentary push button (other pin to ground)
The internal pull-up resistors will be enabled.
Behavior
- If you press the first push button, the LED blinks faster.
- If you press the second push button, the LED blinks slower.
- You can press and hold one of the push buttons to change the frequency by multiple steps.
- If you press both buttons at the same time, the frequency is reset to the initial default frequency.
Written by PieterP, 2019-12-10
https://github.com/tttapa/Arduino-Helpers
buttons.begin();
}
void loop() {
switch (buttons.update()) {
case IncrementDecrementButtons::IncrementShort:
case IncrementDecrementButtons::IncrementLong:
case IncrementDecrementButtons::IncrementHold:
break;
case IncrementDecrementButtons::DecrementShort:
case IncrementDecrementButtons::DecrementLong:
case IncrementDecrementButtons::DecrementHold:
break;
case IncrementDecrementButtons::Reset:
break;
default: break;
}
if (buttons.getState() != IncrementDecrementButtons::Nothing)
}
constexpr PinStatus_t LOW
constexpr PinStatus_t HIGH
constexpr PinMode_t OUTPUT
Dummy header file for Arduino builder.
A class for easily managing timed events.
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
PinStatus_t digitalRead(pin_t pin)
An ExtIO version of the Arduino function.
void digitalWrite(pin_t pin, PinStatus_t val)
An ExtIO version of the Arduino function.
constexpr auto min(const T &a, const U &b) -> decltype(b< a ? b :a)
Return the smaller of two numbers/objects.
constexpr auto max(const T &a, const U &b) -> decltype(a< b ? b :a)
Return the larger of two numbers/objects.