89 lines
3.0 KiB
Markdown
Raw Normal View History

2021-05-30 14:25:11 +02:00
[![Arduino CI](https://github.com/RobTillaart/ShiftInSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-28 11:35:20 +01:00
[![Arduino-lint](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/ShiftInSlow/actions/workflows/jsoncheck.yml)
2021-05-30 14:25:11 +02:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/ShiftInSlow/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/ShiftInSlow.svg?maxAge=3600)](https://github.com/RobTillaart/ShiftInSlow/releases)
2021-12-28 11:35:20 +01:00
2021-05-30 14:25:11 +02:00
# ShiftInSlow
2021-12-28 11:35:20 +01:00
Arduino library for shiftIn with build-in delay - e.g. for 74HC165.
2021-05-30 14:25:11 +02:00
2022-11-24 12:49:27 +01:00
Related libraries
- 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 14:25:11 +02:00
2021-12-28 11:35:20 +01:00
2021-05-30 14:25:11 +02:00
## Description
shiftInSlow is an experimental library that has a build in delay (in microseconds) that allows tuning the time per bit.
This allows one to improve reliability e.g. when using longer lines.
2021-12-28 11:35:20 +01:00
The dataPin and clockPin are set in the constructor, the delay is configurable per byte send to be able to optimize runtime.
2021-05-30 14:25:11 +02:00
## Performance
The performance of **read()** with a delay of 0 microseconds is slower than the default Arduino
**shiftIn()** due to some overhead.
2023-02-21 13:11:46 +01:00
The delay requested is split in two (expect rounding errors) to have "nice" looking pulse
with the duty cycle around 50%.
Performance measurements are meaningless, as the purpose of this library is to
slow the pulse train to a working level.
2021-05-30 14:25:11 +02:00
## Interface
2023-02-21 13:11:46 +01:00
```cpp
#include "ShiftInSlow.h"
```
#### Functions
2021-05-30 14:25:11 +02:00
The interface exists of the following functions:
2022-11-24 12:49:27 +01:00
- **ShiftInSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** constructor,
bit order is default set to LSBFIRST.
2023-02-21 13:11:46 +01:00
- **int read()** reads a new value.
- **int lastRead()** returns last value read.
- **void setDelay(uint16_t microseconds = 0)** set delay per bit from 0 .. 65535 microseconds.
Note that the delay is split in two parts to keep the duty cycle around 50%.
2021-05-30 14:25:11 +02:00
- **uint16_t getDelay()** returns the set delay in microseconds.
2023-02-21 13:11:46 +01:00
- **bool setBitOrder(uint8_t bitOrder = LSBFIRST)** set LSBFIRST or MSBFIRST. Returns false for other values.
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST.
2021-05-30 14:25:11 +02:00
## Operation
2023-02-21 13:11:46 +01:00
See examples.
2021-05-30 14:25:11 +02:00
2021-12-28 11:35:20 +01:00
## Future
2023-02-21 13:11:46 +01:00
#### Must
2021-12-28 11:35:20 +01:00
- improve documentation
2022-11-24 12:49:27 +01:00
2023-02-21 13:11:46 +01:00
#### Should
2021-12-28 11:35:20 +01:00
- add examples
2022-11-24 12:49:27 +01:00
- adaptive speed example?
2023-02-21 13:11:46 +01:00
#### Could
2022-11-24 12:49:27 +01:00
- Add a select pin to be more SPI alike?
2023-02-21 13:11:46 +01:00
- increase max delay uint32_t ?
#### Wont
- get set dutyCycle(0 .. 99%)
2021-12-28 11:35:20 +01:00
- set delay in terms of frequency - delay is 'wave length'
- set delay in terms of max total time the read may cost.
2023-02-21 13:11:46 +01:00
- read16/24/32 to read more bytes is a user task.
2022-11-24 12:49:27 +01:00