GY-63_MS5611/libraries/PinOutGroup
2021-05-28 14:16:25 +02:00
..
.github/workflows add arduino-lint 2021-05-28 13:17:38 +02:00
examples 2021-01-29 2021-01-29 12:31:58 +01:00
test 2021-01-29 2021-01-29 12:31:58 +01:00
.arduino-ci.yml 2021-01-29 2021-01-29 12:31:58 +01:00
keywords.txt 2021-01-29 2021-01-29 12:31:58 +01:00
library.json add license to library,json 2021-05-28 14:16:25 +02:00
library.properties 2021-01-29 2021-01-29 12:31:58 +01:00
LICENSE 2021-01-29 2021-01-29 12:31:58 +01:00
PinOutGroup.cpp 2021-01-29 2021-01-29 12:31:58 +01:00
PinOutGroup.h 2021-01-29 2021-01-29 12:31:58 +01:00
README.md 2021-01-29 2021-01-29 12:31:58 +01:00

Arduino CI License: MIT GitHub release

PinOutGroup

Arduino library to group up to 16 outputs into one command

Description

A PinOutGroup is a number of output pins that can be set by means of one write() command. The PinOutGroup remembers the last values set per pin and will not do a digitalWrite() if the pin is already in the right state. Think of it as caching the state.

If a (group of) pin(s) is updated often this saves cpu cycles however this feature has overhead which works contra productive when you toggle the pins in a group. So use with care.

Performance

Assume that on average 50% of the pins are in the right state in a group. This means that on average half the pins are actually changed. By bypassing the (relative) expensive digitalWrite() time is gained.

Actual performance gains depends very much on the data written. It is worth to do a small investigation for this. See e.g. 7 segment demo.

Note that the pins are not set at the same microsecond. A small time is needed to go through all pins. This is platform, group size and pin state dependent.

Interface

Constructor

  • PinOutGroup() Constructor

Administration

  • clear() resets all pins in the group to LOW and sets the size to zero so one can repopulate.
  • add(size, pinArray, value) adds a predefined array of pins to the group. Returns the number of pins added.
  • add(pin, mode) adds a single pin to the group. Returns the number of pins added (1 or 0). value can be LOW (=0) or HIGH (1 and other values).
  • getPin(idx) idx = 0..15; returns the pin at slot idx or 255 (0xFF) when out of range
  • getIdx(pin) returns the (first) index of the slot with pin number. 255 (0xFF) if not found.
  • isInGroup(pin) returns how often a pin is added to a group. Can be more than once.
  • size() how many slots are used
  • available() how many slots are available

Read / Write

  • write(value) writes a 16 bits unsigned int to max 16 pins.
  • write(idx, value) sets a single pin of the internal array withindex idx to value. This one is faster than writing to the whole group for a single change. The user must keep track of the right index nr.
  • allLOW sets all pins to LOW (this is not same as clear)
  • allHIGH sets all pins to HIGH
  • read() reads back the last written value to the pins as an unsigend int.

Future

  • give clear(skip) a bool flag to skip setting the pins to LOW ?
  • remove function?

Operation

See examples