2021-01-29 12:31:58 +01:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/PinOutGroup/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PinOutGroup/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PinOutGroup.svg?maxAge=3600)](https://github.com/RobTillaart/PinOutGroup/releases)
|
|
|
|
|
2020-05-20 09:53:04 +02:00
|
|
|
# PinOutGroup
|
|
|
|
|
|
|
|
Arduino library to group up to 16 outputs into one command
|
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
## Description
|
2020-05-20 09:53:04 +02:00
|
|
|
|
|
|
|
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
|
2021-01-29 12:31:58 +01:00
|
|
|
has overhead which works contra productive when you toggle the pins in a group.
|
|
|
|
So use with care.
|
|
|
|
|
|
|
|
## Performance
|
2020-05-20 09:53:04 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
**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
|
2020-05-20 09:53:04 +02:00
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
- **clear()** resets all pins in the group to LOW and sets the size to zero
|
2020-05-20 09:53:04 +02:00
|
|
|
so one can repopulate.
|
2021-01-29 12:31:58 +01:00
|
|
|
- **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
|
2020-05-20 09:53:04 +02:00
|
|
|
|
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
### Read / Write
|
2020-05-20 09:53:04 +02:00
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
- **write(value)** writes a 16 bits unsigned int to max 16 pins.
|
|
|
|
- **write(idx, value)** sets a single pin of the internal array withindex
|
2020-05-20 09:53:04 +02:00
|
|
|
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.
|
2021-01-29 12:31:58 +01:00
|
|
|
- **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.
|
2020-05-20 09:53:04 +02:00
|
|
|
|
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
## Future
|
2020-05-20 09:53:04 +02:00
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
- give **clear(skip)** a bool flag to skip setting the pins to LOW ?
|
|
|
|
- remove function?
|
2020-05-20 09:53:04 +02:00
|
|
|
|
2021-01-29 12:31:58 +01:00
|
|
|
## Operation
|
2020-05-20 09:53:04 +02:00
|
|
|
|
|
|
|
See examples
|
|
|
|
|