InputTerminal is an Arduino library for handling multiple digital input keys with short-press and long-press detection.
It is designed for button panels, simple user interfaces, and embedded projects where multiple keys need to be scanned efficiently.
The library uses INPUT_PULLUP mode and represents key states as a bit mask, allowing multiple keys to be detected simultaneously.
- Supports multiple input keys (up to 15 keys)
- Short press and long press detection based on time measurement
- Bit-based key state representation
- Designed for
INPUT_PULLUPwiring (active LOW buttons) - Simple polling-based API
- Works on AVR, ESP32, and other Arduino-compatible platforms
Each button should be wired as follows:
- One side of the button → GPIO pin
- Other side of the button → GND
Internal pull-up resistors are enabled automatically.
[GPIO] ----[ Button ]---- GND
- Download or clone this repository:
git clone https://github.com/hayasita/InputTerminal.git
- Copy the
InputTerminalfolder into your Arduinolibrariesdirectory. - Restart the Arduino IDE.
#include <InputTerminal.h>unsigned char pins[] = {2, 3, 4};
InputTerminal input(pins, 3);Call scan() repeatedly in your loop to update the key state.
void loop() {
input.scan();
unsigned int shortPress = input.read_s();
unsigned int longPress = input.read_l();
if (shortPress) {
// Handle short press
}
if (longPress) {
// Handle long press
}
}Key states are returned as a bit mask:
- Bit
0→ key 0 - Bit
1→ key 1 - Bit
2→ key 2 - ...
Example:
0b00000101This means key 0 and key 2 are pressed.
Scans all input pins and updates the internal state.
This function must be called periodically (e.g. in loop()).
Returns both short-press and long-press events combined (bitwise OR).
Reading clears the stored events.
Returns short-press events only.
Reading clears the stored short-press events.
Returns long-press events only.
Reading clears the stored long-press events.
Sets the short-press detection time in milliseconds.
Sets the long-press detection time in milliseconds.
Returns the number of configured input keys.
Returns the error code:
0x00: No error0x01: Too many keys configured
- Maximum number of keys is limited to 15 due to bit-based representation.
- The library internally uses
millis()for timing. - The current implementation uses static variables inside
scan(), so using multiple instances simultaneously is not recommended without modification.
This library is released under the MIT License.
See the LICENSE file for details.
- hayasita