2021-05-30 08:25:53 -04:00
|
|
|
|
|
|
|
[![Arduino CI](https://github.com/RobTillaart/ShiftOutSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
2021-12-28 05:53:42 -05:00
|
|
|
[![Arduino-lint](https://github.com/RobTillaart/ShiftOutSlow/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ShiftOutSlow/actions/workflows/arduino-lint.yml)
|
|
|
|
[![JSON check](https://github.com/RobTillaart/ShiftOutSlow/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ShiftOutSlow/actions/workflows/jsoncheck.yml)
|
2023-11-22 04:22:11 -05:00
|
|
|
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/ShiftOutSlow.svg)](https://github.com/RobTillaart/ShiftOutSlow/issues)
|
|
|
|
|
2021-05-30 08:25:53 -04:00
|
|
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ShiftOutSlow/blob/master/LICENSE)
|
|
|
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ShiftOutSlow.svg?maxAge=3600)](https://github.com/RobTillaart/ShiftOutSlow/releases)
|
2023-11-22 04:22:11 -05:00
|
|
|
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/ShiftOutSlow.svg)](https://registry.platformio.org/libraries/robtillaart/ShiftOutSlow)
|
2021-05-30 08:25:53 -04:00
|
|
|
|
2021-12-28 05:53:42 -05:00
|
|
|
|
2021-05-30 08:25:53 -04:00
|
|
|
# ShiftOutSlow
|
|
|
|
|
|
|
|
Arduino library for shiftOut with build-in delay - e.g. for 74HC595
|
|
|
|
|
2021-12-28 05:53:42 -05:00
|
|
|
|
2021-05-30 08:25:53 -04:00
|
|
|
## Description
|
|
|
|
|
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
ShiftOutSlow is an experimental library that has a build in delay (in microseconds) that allows tuning the time per bit.
|
2021-05-30 08:25:53 -04:00
|
|
|
This allows one to improve reliability e.g. when using longer lines.
|
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
The data pin and clock pin are set in the constructor, the delay can be set per byte send to be able to optimize runtime.
|
2021-05-30 08:25:53 -04:00
|
|
|
|
|
|
|
ShiftOutSlow implements the print interface.
|
|
|
|
|
|
|
|
|
2023-11-22 04:22:11 -05:00
|
|
|
#### Related
|
|
|
|
|
|
|
|
- https://github.com/RobTillaart/FastShiftIn
|
|
|
|
- https://github.com/RobTillaart/FastShiftOut
|
|
|
|
- https://github.com/RobTillaart/FastShiftInOut
|
|
|
|
- https://github.com/RobTillaart/ShiftInSlow
|
|
|
|
- https://github.com/RobTillaart/ShiftOutSlow
|
|
|
|
|
|
|
|
|
2021-05-30 08:25:53 -04:00
|
|
|
## Performance
|
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
The performance of **write()** with a delay of 0 microseconds is slower than the default Arduino
|
|
|
|
**shiftOut()** due to some overhead.
|
2021-05-30 08:25:53 -04:00
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
The delay requested is divided by two to minimize disruption of the duty cycle of the clock pulse,
|
|
|
|
resulting in "better" pulses.
|
2021-05-30 08:25:53 -04:00
|
|
|
|
2023-11-22 04:22:11 -05:00
|
|
|
Performance measurements are meaningless, as the purpose of this library is to
|
|
|
|
slow the pulse train to a working level.
|
|
|
|
|
2021-05-30 08:25:53 -04:00
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
2023-02-21 08:13:13 -05:00
|
|
|
```cpp
|
|
|
|
#include "ShiftOutSlow.h"
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Functions
|
|
|
|
|
2021-05-30 08:25:53 -04:00
|
|
|
The interface exists of the following functions:
|
2021-08-16 13:25:37 -04:00
|
|
|
|
2021-12-28 05:53:42 -05:00
|
|
|
- **ShiftOutSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** constructor.
|
2023-02-21 08:13:13 -05:00
|
|
|
- **size_t write(uint8_t data)** writes a new value.
|
|
|
|
Returns the bytes written.
|
|
|
|
- **size_t write(const uint8_t \*buffer, size_t size)** writes an array of size over shift out.
|
|
|
|
Uses **write(uint8_t)** so expect about equal performance.
|
|
|
|
Returns the bytes written.
|
2021-08-16 13:25:37 -04:00
|
|
|
- **uint8_t lastWritten()** returns last value written.
|
2023-02-21 08:13:13 -05:00
|
|
|
- **void setDelay(uint16_t microSeconds = 0)** set delay per **bit** from 0 .. 65535 microseconds.
|
|
|
|
Note: the delay is not the time per bit but an additional time per bit.
|
2021-08-16 13:25:37 -04:00
|
|
|
Note: the delay can be set runtime per write / print call.
|
2021-05-30 08:25:53 -04:00
|
|
|
- **uint16_t getDelay()** returns the set delay in microseconds.
|
2023-02-21 08:13:13 -05:00
|
|
|
- **bool setBitOrder(uint8_t bitOrder = LSBFIRST)** set LSBFIRST or MSBFIRST.
|
|
|
|
Returns false for other values.
|
2021-12-28 05:53:42 -05:00
|
|
|
Note: bit order can be changed runtime per write / print call.
|
2023-02-21 08:13:13 -05:00
|
|
|
- **uint8_t getBitOrder()** returns LSBFIRST or MSBFIRST (typical 0 and 1).
|
2021-08-16 13:25:37 -04:00
|
|
|
|
2021-05-30 08:25:53 -04:00
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
### Print interface
|
2021-05-30 08:25:53 -04:00
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
As this library implements the print interface one can use:
|
2021-05-30 08:25:53 -04:00
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
- **size_t print(any)** print any data type.
|
|
|
|
- **size_t println(any)** print any data type followed by a newline "\n".
|
2021-05-30 08:25:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
## Operation
|
|
|
|
|
2021-08-16 13:25:37 -04:00
|
|
|
See examples.
|
|
|
|
|
|
|
|
|
|
|
|
## Future
|
|
|
|
|
2023-02-21 08:13:13 -05:00
|
|
|
#### Must
|
|
|
|
|
2021-12-28 05:53:42 -05:00
|
|
|
- improve documentation
|
2022-11-24 06:51:14 -05:00
|
|
|
|
2023-02-21 08:13:13 -05:00
|
|
|
#### Should
|
|
|
|
|
2023-11-22 04:22:11 -05:00
|
|
|
- Add a select pin to be more SPI alike?
|
|
|
|
- would allow SPI debugging?
|
|
|
|
- increase max delay uint32_t ?
|
|
|
|
- would allow pulses in "second" domain.
|
|
|
|
|
|
|
|
#### Could
|
|
|
|
|
2021-12-28 05:53:42 -05:00
|
|
|
- add examples
|
2022-11-24 06:51:14 -05:00
|
|
|
- adaptive speed example?
|
2023-02-21 08:13:13 -05:00
|
|
|
|
|
|
|
#### Wont
|
|
|
|
|
2023-11-22 04:22:11 -05:00
|
|
|
- delay/2 is not exact half when delay is odd.
|
|
|
|
- no big issue.
|
|
|
|
- del_before and del_after could prepare for duty cycle.
|
2021-12-28 05:53:42 -05:00
|
|
|
- set delay in terms of frequency - delay is 'wave length'
|
|
|
|
- set delay in terms of max total time the read may cost.
|
|
|
|
- get set dutyCycle(0 .. 99%)
|
|
|
|
- optimize the place to yield() ?
|
2023-11-22 04:22:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
## Support
|
|
|
|
|
|
|
|
If you appreciate my libraries, you can support the development and maintenance.
|
|
|
|
Improve the quality of the libraries by providing issues and Pull Requests, or
|
|
|
|
donate through PayPal or GitHub sponsors.
|
|
|
|
|
|
|
|
Thank you,
|
|
|
|
|