GY-63_MS5611/libraries/shiftInSlow/README.md

62 lines
2.5 KiB
Markdown
Raw Normal View History

2021-05-30 08:25:11 -04:00
[![Arduino CI](https://github.com/RobTillaart/ShiftInSlow/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-28 05:35:20 -05: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 08:25:11 -04: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 05:35:20 -05:00
2021-05-30 08:25:11 -04:00
# ShiftInSlow
2021-12-28 05:35:20 -05:00
Arduino library for shiftIn with build-in delay - e.g. for 74HC165.
2021-05-30 08:25:11 -04:00
A library for shiftOutSlow also exist.
2021-12-28 05:35:20 -05:00
2021-05-30 08:25:11 -04: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 05:35:20 -05: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 08:25:11 -04:00
## Performance
The performance of **read()** with a delay of 0 microseconds is slower than the default Arduino
**shiftIn()** due to some overhead.
The delay requested is split in two (expect rounding errors) to have "nice" looking pulses.
2021-12-28 05:35:20 -05:00
This keeps the duty cycle ~50%.
2021-05-30 08:25:11 -04:00
## Interface
The interface exists of the following functions:
2021-12-28 05:35:20 -05:00
- **ShiftInSlow(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder = LSBFIRST)** constructor, bit order is default set to LSBFIRST.
2021-05-30 08:25:11 -04:00
- **int read(void)** reads a new value
- **int lastRead()** returns last value read
2021-12-28 05:35:20 -05:00
- **void setDelay(uint16_t microseconds)** set delay per bit from 0 .. 65535 microseconds. Note that the delay is split in two parts to keep ~ 50% duty cycle.
2021-05-30 08:25:11 -04:00
- **uint16_t getDelay()** returns the set delay in microseconds.
2021-12-28 05:35:20 -05:00
- **bool setBitOrder(uint8_t bitOrder)** set LSBFIRST or MSBFIRST. Returns false for other values.
2021-05-30 08:25:11 -04:00
- **uint8_t getBitOrder(void)** returns LSBFIRST or MSBFIRST
## Operation
See examples
2021-12-28 05:35:20 -05:00
## Future
- Add a select pin to be more SPI alike?
- improve documentation
- add examples
- increase max delay uint32_t ?
- set delay in terms of frequency - delay is 'wave length'
- set delay in terms of max total time the read may cost.
- set default delay = 0, is no delay ?
- adaptive speed example?
- get set dutyCycle(0 .. 99%)
-