Main Content

Digital IO library

This goal of this Digital I/O library is to ease the use of simple sensors and devices attached to Digital I/O pins.

If you like this library please star or comment on github to pat me in the back and let others know it exists

Benefits
It can debounce noisy signals to avoid program glitches
It has level and spike detection to support things like button presses or transient knock sensor signals.
It is nimble and compact. Classes use the minimum amount of RAM to hold data (usually 1 byte), and classes rely on constant folding to optimize codewithout sacrificing functionality. Methods often take less program memory than equivalent native Arduino code. AVR specific version of the classes access AVR ports directly to generate faster code that is often 15% smaller. The choice to use Arduino pins or AVR ports is one line change at the declaration of your variable.
Classes support interrupt and non-interrupt modes. With interrupts, I/O pins signals are less likely to be missed, and the code is more responsive. Non-interrupt is more flexible as few I/O pins are associated with interrupts. The choice is made by setting one flag when declaring your variable.
Class interfaces are simple, intuitive and descriptive, making your code easier to read, hence less buggy. For example: “if (button.isOn()) {led.turnOn();}” is much easier to read than “if (button.read()==LOW){led.write(HIGH);}”
The library comes with a TaskManager class which help you write concurrent code. You can schedule a function to run at a regular time interval with one line of code. It uses Timer0 (the Arduino clock timer) so it doesn’t prevent you to use the other timers for other purposes.
Hardware supported
The DigitalIo library targets all the simple devices and sensors that attach to one or more Digital I/O pins. It can handle mechanical and solid state devices that have simple often custom communication protocols.

You could use the native Arduino methods digitalRead() and digitalWrite() directly to perform I/O on the digital pins, but the resulting code would be messier, hard to reuse and maintain, less performant, and you would need to debounce signals yourself. With AVR microcontroller boards, this code is also slower because the Arduino translation layer converts the pin number to AVR ports using tables stored in PROGMEM.

Simple Sensors:

They usually behave either like ON/OFF contacts or like transient contacts

Push button switches and toggles
KS0024 Bump Sensor or Knock Sensor
KS0025 Tilt Digital Motion Sensor
Tilt Switch
KY-017 Mercury Switch
A3144 Hall sensor switch
KS0038 Reed Switch
HC-SR501 Infrared Passive Infrared PIR Motion Sensor (on when LOW)
Other Sensors:

Some sensors have more complex communication protocols, but are not standard I2C or SPI. The DigitalIo library has classes that support these:

Rotary Encoders
Motor Encoders
Sonar
Ultrasonic Sensor”

Link to article