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

95 lines
3.2 KiB
Markdown
Raw Permalink Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/AsyncAnalog/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-10-19 05:14:50 -04:00
[![Arduino-lint](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AsyncAnalog/actions/workflows/jsoncheck.yml)
2023-10-17 13:46:28 -04:00
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/AsyncAnalog.svg)](https://github.com/RobTillaart/AsyncAnalog/issues)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AsyncAnalog/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AsyncAnalog.svg?maxAge=3600)](https://github.com/RobTillaart/AsyncAnalog/releases)
2023-10-17 13:46:28 -04:00
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/AsyncAnalog.svg)](https://registry.platformio.org/libraries/robtillaart/AsyncAnalog)
2021-01-29 06:31:58 -05:00
2021-10-19 05:14:50 -04:00
2021-01-29 06:31:58 -05:00
# AsyncAnalog
2021-12-13 13:46:42 -05:00
Arduino Library for async reading of an analogue pin. **\[AVR ONLY\]**.
2021-01-29 06:31:58 -05:00
## Description
2021-10-19 05:14:50 -04:00
2023-10-17 13:46:28 -04:00
AsyncAnalog is a library to read the analogue port of an **AVR** in an asynchronous way.
2024-04-06 14:00:19 -04:00
This means that the user must explicitly **start()** the ADC, check if it is **ready()**
and read its **value()**.
2021-01-29 06:31:58 -05:00
By using this class, the user prevents the (~112 uSec) blocking of the
**analogRead()** call, and gives the user the ability to do some processing.
The library works only for AVR boards now, other platforms might be supported in the future.
2024-04-06 14:00:19 -04:00
(PR's are welcome).
2021-01-29 06:31:58 -05:00
2023-10-17 13:46:28 -04:00
**WARNING**
2024-04-06 14:00:19 -04:00
As the UNO has only one ADC that is multiplexed, one can only read one analog pin
in async way simultaneously. Still it offers to about 100 micros to do something!
2021-01-29 06:31:58 -05:00
2021-12-13 13:46:42 -05:00
**Use with care**
2021-01-29 06:31:58 -05:00
2024-04-06 14:00:19 -04:00
#### Related
- https://github.com/RobTillaart/AnalogPin
2023-10-17 13:46:28 -04:00
## Interface
```cpp
#include "AsynAnalog,h"
```
2021-01-29 06:31:58 -05:00
2021-10-19 05:14:50 -04:00
- **AsyncAnalog(uint8_t pin)** constructor, defines the analogue pin to use.
2024-04-06 14:00:19 -04:00
- **void start()** triggers a new ADC measurement.
- **bool ready()** Checks if the measurement is completed.
If so the value is calculated and cached for **value()**.
As long as ready() is not called the old value will not change!
- **uint16_t value()** returns the value of the ADC from cache.
So it will return the same value even if the internal ADC is used to sample
another analog port.
2021-01-29 06:31:58 -05:00
2021-10-19 05:14:50 -04:00
2021-01-29 06:31:58 -05:00
## Operation
The example **asyncAnalogTest2.ino** shows a loop of 1000 analogReads and prints
2021-12-13 13:46:42 -05:00
over Serial at 115200 baud.
2021-01-29 06:31:58 -05:00
2021-10-19 05:14:50 -04:00
## Future
2023-10-17 13:46:28 -04:00
#### Must
2024-04-06 14:00:19 -04:00
- improve documentation.
2023-10-17 13:46:28 -04:00
#### Should
2024-04-06 14:00:19 -04:00
- create examples
- real world examples preferred.
- multi ADC, e.g. A0..A4
2023-10-17 13:46:28 -04:00
#### Could
2021-12-13 13:46:42 -05:00
- investigate the performance gain.
2023-10-17 13:46:28 -04:00
- asyncAnalogTest2.ino is not a good test.
2021-10-19 05:14:50 -04:00
- investigate other platforms
- fall back to normal analogRead for non AVR platforms ?
2024-04-06 14:00:19 -04:00
- start would be analogRead() and it would immediately be ready and the value is cached.
2023-10-17 13:46:28 -04:00
- better have specific code per platform.
#### Wont
## 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,
2021-10-19 05:14:50 -04:00