GY-63_MS5611/libraries/AnalogPin
2022-10-28 21:33:10 +02:00
..
.github add funding.yml 2022-08-03 21:56:07 +02:00
examples 0.2.6 AnalogPin 2021-12-12 15:57:24 +01:00
test 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00
.arduino-ci.yml 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00
AnalogPin.cpp 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00
AnalogPin.h 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00
CHANGELOG.md 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00
keywords.txt 0.2.6 AnalogPin 2021-12-12 15:57:24 +01:00
library.json 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00
library.properties 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00
LICENSE 0.2.6 AnalogPin 2021-12-12 15:57:24 +01:00
README.md 0.2.7 AnalogPin 2022-10-28 21:33:10 +02:00

Arduino CI Arduino-lint JSON check License: MIT GitHub release

AnalogPin

Arduino library to add functionality on top of analogRead().

Description

AnalogPin is an Arduino class that adds noise filtering and smoothing to analogRead(). Furthermore it can speed up the analogRead() function by tuning the pre-scaler. This latter is AVR only.

Interface

  • AnalogPin(uint8_t pin) constructor with analogue pin as parameter.
  • void setPrescaler(uint8_t prescale = 7) AVR only pre-scaler.
  • uint8_t getPrescaler() return pre-scaler set.
  • void setNoiseThreshold(uint8_t noise = 0) set noise level that should be ignored. Typical 0..2.
  • uint8_t getNoiseThreshold() return set value.
  • void setSmoothWeight(uint8_t alpha = 0) alpha = 0..31, parameter for low pass filter.
  • uint8_t getSmoothWeight(void) returns set alpha.
  • int read(bool twice = false) read function, optional read twice to stabilize.
  • int readSmoothed() read version that uses low pass filter.
  • int readPrevious() returns previous read value.
  • int readLast() returns last read value without reading a new one.

Operation

get/setPrescaler(uint8_t prescale) can be used to speed up analogRead().
The effect is that both the accuracy and precision are affected. You should verify if this is acceptable for your project. Works only for AVR based boards

get/setNoiseThreshold(uint8_t noise) is used to set the noise threshold to be used by the read() function.

read(bool twice) implements an analogRead() that suppresses small noise fluctuations. The parameter twice is used to force analogRead() to be executed twice to reduce noise from the multiplexing.

Example: if the previous read has the value 300 and you want to interpret all subsequent readings between 290 and 310 as 300 (the same) your code should look like:

    AP.setNoiseThreshold(10);
    AP.read();

get/setSmoothWeight(uint8_t alpha) is used to set the weight factor for the readSmoothed() function.

The weight of the previous read is alpha/32. A higher alpha will dampen the signal more, a lower alpha will follow the actual signal better. This can be used to suppress noise too.

    AP.setSmoothWeight(4);   // weight = 4/32 = 1/8 = 12.5%
    AP.readSmoothed();

readSmoothed() implements an analogRead with a running average build in.

Future

  • update documentation
    • advantage of certain functions, when to use
  • more examples
  • volts() + get/setFactor(float f)
  • move code to .cpp