Skip to content

hayasita/InputTerminal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

InputTerminal

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.


Features

  • 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_PULLUP wiring (active LOW buttons)
  • Simple polling-based API
  • Works on AVR, ESP32, and other Arduino-compatible platforms

Wiring

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

Installation

Manual Installation

  1. Download or clone this repository:
    git clone https://github.com/hayasita/InputTerminal.git
  2. Copy the InputTerminal folder into your Arduino libraries directory.
  3. Restart the Arduino IDE.

Usage

Include the library

#include <InputTerminal.h>

Create an instance

unsigned char pins[] = {2, 3, 4};

InputTerminal input(pins, 3);

Main loop

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 Data Format

Key states are returned as a bit mask:

  • Bit 0 → key 0
  • Bit 1 → key 1
  • Bit 2 → key 2
  • ...

Example:

0b00000101

This means key 0 and key 2 are pressed.


API Reference

void scan()

Scans all input pins and updates the internal state.
This function must be called periodically (e.g. in loop()).


unsigned int read()

Returns both short-press and long-press events combined (bitwise OR).
Reading clears the stored events.


unsigned int read_s()

Returns short-press events only.
Reading clears the stored short-press events.


unsigned int read_l()

Returns long-press events only.
Reading clears the stored long-press events.


void set_keychktim_s(unsigned int ms)

Sets the short-press detection time in milliseconds.


void set_keychktim_l(unsigned int ms)

Sets the long-press detection time in milliseconds.


unsigned char read_tmnum()

Returns the number of configured input keys.


unsigned char read_err()

Returns the error code:

  • 0x00 : No error
  • 0x01 : Too many keys configured

Notes

  • 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.

License

This library is released under the MIT License.
See the LICENSE file for details.


Author

  • hayasita

About

Library of Arduino for the input terminal.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages