New library for digital read/write/pinmode

Seems like the right place to post this.


github excerpt:


This library replaces Arduino AVR Core functions with smaller and faster versions.
For example, the Blink example sketch built for the Uno is 284 bytes smaller with ArduinoShrink.

I built a retriggerable timer sketch - there have been a lot of posts about such lately - and included this library. It does what it says. In fact, it works so well I had to modify the original code a bit (on the author’s recommendation) to account for the increased speed.

As to memory used, without *ArduinoShrink * flash usage is 2428 bytes. When *ArduinoShrink * is included that drops to 1952 bytes, a reduction of 476 bytes.

My test sketch:

// retriggerable/watchdog timer



#include <ArduinoShrink.h> // Library speeds and shrinks I/O operations

unsigned long lastMillis;
unsigned long preset = 1000;
boolean timedOut = true;
boolean lastSignal; // trigger memory
boolean watchDogEnabled = false;
byte inputSignal = A3; // timer trigger input - tactile switch for testing
byte externalLED = 7; // LED wired common anode

void setup() {
  pinMode(inputSignal, INPUT_PULLUP);
  digitalWrite(externalLED, HIGH);
  pinMode(externalLED, OUTPUT);
  //  Serial.println(__FILE__);
  // delayMicroseconds() allows 1-2us for input pin to stabilize before
  // reading its state.  Necessary since inclusion of ArduinoShrink
  // library greatly increases speed of I/O operations.
  // Reference links above.
  lastSignal = digitalRead(inputSignal); // initialize signal state to input

void loop() {
  // a free-running timer controls its completion status
  if (millis() - lastMillis < preset)
    timedOut = false;
  else timedOut = true;

  // the free-running timer is reset if the trigger changes
  if (lastSignal != digitalRead(inputSignal)) {
    lastMillis = millis(); // Reset timer
    watchDogEnabled = true;
  lastSignal = digitalRead(inputSignal); // Reset the timer trigger

  // If trigger is unchanged for xx ms, timer times out
  // and turns off external LED (active low)
  if (watchDogEnabled) {
    digitalWrite(externalLED, timedOut);
  Serial.print(millis() - lastMillis); // display timer value