From 909bcdb0c4ba7b6491a58c84b5c21e550747f061 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Sun, 12 Dec 2021 15:57:24 +0100 Subject: [PATCH] 0.2.6 AnalogPin --- libraries/AnalogPin/AnalogPin.cpp | 5 ++++- libraries/AnalogPin/AnalogPin.h | 8 +++++--- libraries/AnalogPin/LICENSE | 2 +- libraries/AnalogPin/README.md | 17 ++++++++++------- .../AnalogPin/examples/AnalogPin/AnalogPin.ino | 6 +++++- .../AnalogPin_prescaler/AnalogPin_prescaler.ino | 8 ++++++++ libraries/AnalogPin/keywords.txt | 7 +++++-- libraries/AnalogPin/library.json | 5 +++-- libraries/AnalogPin/library.properties | 2 +- libraries/AnalogPin/test/unit_test_001.cpp | 6 ++++++ 10 files changed, 48 insertions(+), 18 deletions(-) diff --git a/libraries/AnalogPin/AnalogPin.cpp b/libraries/AnalogPin/AnalogPin.cpp index 6078af87..4bd8c046 100644 --- a/libraries/AnalogPin/AnalogPin.cpp +++ b/libraries/AnalogPin/AnalogPin.cpp @@ -1,7 +1,7 @@ // // FILE: AnalogPin.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.5 +// VERSION: 0.2.6 // DATE: 2013-09-09 // PURPOSE: wrapper for analogRead with smoothing and noise filtering // @@ -17,6 +17,7 @@ // 0.2.3 2020-05-27 update library.json // 0.2.4 2020-12-10 add Arduino-ci // 0.2.5 2021-10-17 update Arduino-CI +// 0.2.6 2021-12-12 update library.json, license, minor edits. #include "AnalogPin.h" @@ -96,4 +97,6 @@ void AnalogPin::_rawRead() #endif } + // -- END OF FILE -- + diff --git a/libraries/AnalogPin/AnalogPin.h b/libraries/AnalogPin/AnalogPin.h index 01586222..08c39b0f 100644 --- a/libraries/AnalogPin/AnalogPin.h +++ b/libraries/AnalogPin/AnalogPin.h @@ -2,7 +2,7 @@ // // FILE: AnalogPin.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.5 +// VERSION: 0.2.6 // DATE: 2013-09-09 // PURPOSE: wrapper for analogRead with smoothing and noise filtering // URL: https://github.com/RobTillaart/AnalogPin @@ -11,7 +11,7 @@ #include "Arduino.h" -#define ANALOGPIN_LIB_VERSION (F("0.2.5")) +#define ANALOGPIN_LIB_VERSION (F("0.2.6")) class AnalogPin @@ -20,7 +20,7 @@ public: explicit AnalogPin(const uint8_t pin); - // prescale = { 2..7 }, imho 2 is bad, 3 is pretty noisy, 4 and 5 are acceptable, 6 and 7 are good. Depends on project!!! + // prescale = { 2..7 }, 2 is bad, 3 is pretty noisy, 4 and 5 are acceptable, 6 and 7 are good. Depends on project!!! // time indication per analogRead for different prescale values on UNO // 2 => 14 uSec 5 => 38 uSec // 3 => 18 uSec 6 => 63 uSec @@ -56,4 +56,6 @@ private: int _prevValue; }; + // -- END OF FILE -- + diff --git a/libraries/AnalogPin/LICENSE b/libraries/AnalogPin/LICENSE index 0637a28b..4feba6f8 100644 --- a/libraries/AnalogPin/LICENSE +++ b/libraries/AnalogPin/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2014-2021 Rob Tillaart +Copyright (c) 2014-2022 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/AnalogPin/README.md b/libraries/AnalogPin/README.md index b0635d64..3f478477 100644 --- a/libraries/AnalogPin/README.md +++ b/libraries/AnalogPin/README.md @@ -8,13 +8,12 @@ # AnalogPin -Arduino library to add functionality on top of analogRead() +Arduino library to add functionality on top of analogRead(). ## Description -AnalogPin is an Arduino class that adds noise filtering and smoothing -to analogRead(). +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. @@ -37,14 +36,14 @@ This latter is AVR only. ## Operation -**get/setPrescaler(prescale)** can be used to speed up analogRead(). +**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(noise)** is used to set the noise threshold to be used by the **read()** function. +**get/setNoiseThreshold(uint8_t noise)** is used to set the noise threshold to be used by the **read()** function. -**read(twice)** implements an **analogRead()** that suppresses small noise fluctuations. +**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 @@ -55,7 +54,7 @@ and 310 as 300 (the same) your code should look like: AP.read(); ``` -**get/setSmoothWeight(alpha)** is used to set the weight factor for the **readSmoothed()** function. +**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 @@ -72,6 +71,10 @@ This can be used to suppress noise too. ## Future +- update documentation + - advantage of certain functions, when to use - more examples +- **volts()** + get/setFactor(float f) + - diff --git a/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino b/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino index 199e4db2..8b2a0568 100644 --- a/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino +++ b/libraries/AnalogPin/examples/AnalogPin/AnalogPin.ino @@ -6,6 +6,7 @@ // URL: https://github.com/RobTillaart/AnalogPin // + #include "AnalogPin.h" AnalogPin INA(A0); @@ -14,6 +15,7 @@ AnalogPin INB(A1); uint32_t start, stop; uint32_t val; + void setup() { Serial.begin(115200); @@ -66,7 +68,7 @@ void setup() Serial.print("VALUE:\t "); Serial.println(val / 1000); - Serial.println("\nINB.read() - prescaler=5"); + Serial.println("\nINB.read() - prescale = 5"); val = 0; start = millis(); for (int i = 0; i < 1000; i++) @@ -94,4 +96,6 @@ void loop() delay(1000); } + // -- END OF FILE -- + diff --git a/libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino b/libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino index cb9460dd..db692661 100644 --- a/libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino +++ b/libraries/AnalogPin/examples/AnalogPin_prescaler/AnalogPin_prescaler.ino @@ -6,13 +6,16 @@ // URL: https://github.com/RobTillaart/AnalogPin // + #include "AnalogPin.h" + AnalogPin AR(A0); uint32_t start, stop; uint32_t val; + void setup() { Serial.begin(115200); @@ -44,6 +47,11 @@ void setup() Serial.println("\nDone..."); } + void loop() { } + + +// -- END OF FILE -- + diff --git a/libraries/AnalogPin/keywords.txt b/libraries/AnalogPin/keywords.txt index 1d9779ba..84f1878a 100644 --- a/libraries/AnalogPin/keywords.txt +++ b/libraries/AnalogPin/keywords.txt @@ -1,15 +1,18 @@ -# Syntax Coloring Map For AnalogPin +# Syntax Colouring Map For AnalogPin -# Datatypes (KEYWORD1) +# Data types (KEYWORD1) AnalogPin KEYWORD1 # Methods and Functions (KEYWORD2) setPrescaler KEYWORD2 getPrescaler KEYWORD2 + setNoiseThreshold KEYWORD2 getNoiseThreshold KEYWORD2 + setSmoothWeight KEYWORD2 getSmoothWeight KEYWORD2 + read KEYWORD2 readSmoothed KEYWORD2 readPrevious KEYWORD2 diff --git a/libraries/AnalogPin/library.json b/libraries/AnalogPin/library.json index ec107585..769ab312 100644 --- a/libraries/AnalogPin/library.json +++ b/libraries/AnalogPin/library.json @@ -15,8 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/AnalogPin" }, - "version": "0.2.5", + "version": "0.2.6", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "AnalogPin.h" } diff --git a/libraries/AnalogPin/library.properties b/libraries/AnalogPin/library.properties index 786a9a42..d61415d7 100644 --- a/libraries/AnalogPin/library.properties +++ b/libraries/AnalogPin/library.properties @@ -1,5 +1,5 @@ name=AnalogPin -version=0.2.5 +version=0.2.6 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino Library for AnalogPin diff --git a/libraries/AnalogPin/test/unit_test_001.cpp b/libraries/AnalogPin/test/unit_test_001.cpp index 33bf774e..4db99ca7 100644 --- a/libraries/AnalogPin/test/unit_test_001.cpp +++ b/libraries/AnalogPin/test/unit_test_001.cpp @@ -29,6 +29,7 @@ unittest_setup() { } + unittest_teardown() { } @@ -36,6 +37,8 @@ unittest_teardown() unittest(test_constructor) { + fprintf(stderr, "ANALOGPIN_LIB_VERSION: %s\n", (char *) ANALOGPIN_LIB_VERSION); + AnalogPin AP(0); // A0 not supported assertEqual(7, AP.getPrescaler()); @@ -65,6 +68,7 @@ unittest(test_prescaler) } } + unittest(test_noiseThreshold) { AnalogPin AP(0); @@ -76,6 +80,7 @@ unittest(test_noiseThreshold) } } + unittest(test_smooth) { AnalogPin AP(0); @@ -87,6 +92,7 @@ unittest(test_smooth) } } + unittest(test_read) { AnalogPin AP(0);