0.2.6 AnalogPin

This commit is contained in:
rob tillaart 2021-12-12 15:57:24 +01:00
parent 88af89a113
commit 909bcdb0c4
10 changed files with 48 additions and 18 deletions

View File

@ -1,7 +1,7 @@
// //
// FILE: AnalogPin.cpp // FILE: AnalogPin.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.2.5 // VERSION: 0.2.6
// DATE: 2013-09-09 // DATE: 2013-09-09
// PURPOSE: wrapper for analogRead with smoothing and noise filtering // PURPOSE: wrapper for analogRead with smoothing and noise filtering
// //
@ -17,6 +17,7 @@
// 0.2.3 2020-05-27 update library.json // 0.2.3 2020-05-27 update library.json
// 0.2.4 2020-12-10 add Arduino-ci // 0.2.4 2020-12-10 add Arduino-ci
// 0.2.5 2021-10-17 update 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" #include "AnalogPin.h"
@ -96,4 +97,6 @@ void AnalogPin::_rawRead()
#endif #endif
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,7 +2,7 @@
// //
// FILE: AnalogPin.h // FILE: AnalogPin.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.2.5 // VERSION: 0.2.6
// DATE: 2013-09-09 // DATE: 2013-09-09
// PURPOSE: wrapper for analogRead with smoothing and noise filtering // PURPOSE: wrapper for analogRead with smoothing and noise filtering
// URL: https://github.com/RobTillaart/AnalogPin // URL: https://github.com/RobTillaart/AnalogPin
@ -11,7 +11,7 @@
#include "Arduino.h" #include "Arduino.h"
#define ANALOGPIN_LIB_VERSION (F("0.2.5")) #define ANALOGPIN_LIB_VERSION (F("0.2.6"))
class AnalogPin class AnalogPin
@ -20,7 +20,7 @@ public:
explicit AnalogPin(const uint8_t pin); 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 // time indication per analogRead for different prescale values on UNO
// 2 => 14 uSec 5 => 38 uSec // 2 => 14 uSec 5 => 38 uSec
// 3 => 18 uSec 6 => 63 uSec // 3 => 18 uSec 6 => 63 uSec
@ -56,4 +56,6 @@ private:
int _prevValue; int _prevValue;
}; };
// -- END OF FILE -- // -- END OF FILE --

View File

@ -1,6 +1,6 @@
MIT License 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -8,13 +8,12 @@
# AnalogPin # AnalogPin
Arduino library to add functionality on top of analogRead() Arduino library to add functionality on top of analogRead().
## Description ## Description
AnalogPin is an Arduino class that adds noise filtering and smoothing AnalogPin is an Arduino class that adds noise filtering and smoothing to analogRead().
to analogRead().
Furthermore it can speed up the analogRead() function by tuning the pre-scaler. Furthermore it can speed up the analogRead() function by tuning the pre-scaler.
This latter is AVR only. This latter is AVR only.
@ -37,14 +36,14 @@ This latter is AVR only.
## Operation ## 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. The effect is that both the accuracy and precision are affected.
You should verify if this is acceptable for your project. You should verify if this is acceptable for your project.
***Works only for AVR based boards*** ***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. 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 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(); 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**. The weight of the previous read is **alpha/32**.
A higher alpha will dampen the signal more, a lower alpha A higher alpha will dampen the signal more, a lower alpha
@ -72,6 +71,10 @@ This can be used to suppress noise too.
## Future ## Future
- update documentation
- advantage of certain functions, when to use
- more examples - more examples
- **volts()** + get/setFactor(float f)
-

View File

@ -6,6 +6,7 @@
// URL: https://github.com/RobTillaart/AnalogPin // URL: https://github.com/RobTillaart/AnalogPin
// //
#include "AnalogPin.h" #include "AnalogPin.h"
AnalogPin INA(A0); AnalogPin INA(A0);
@ -14,6 +15,7 @@ AnalogPin INB(A1);
uint32_t start, stop; uint32_t start, stop;
uint32_t val; uint32_t val;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -66,7 +68,7 @@ void setup()
Serial.print("VALUE:\t "); Serial.print("VALUE:\t ");
Serial.println(val / 1000); Serial.println(val / 1000);
Serial.println("\nINB.read() - prescaler=5"); Serial.println("\nINB.read() - prescale = 5");
val = 0; val = 0;
start = millis(); start = millis();
for (int i = 0; i < 1000; i++) for (int i = 0; i < 1000; i++)
@ -94,4 +96,6 @@ void loop()
delay(1000); delay(1000);
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -6,13 +6,16 @@
// URL: https://github.com/RobTillaart/AnalogPin // URL: https://github.com/RobTillaart/AnalogPin
// //
#include "AnalogPin.h" #include "AnalogPin.h"
AnalogPin AR(A0); AnalogPin AR(A0);
uint32_t start, stop; uint32_t start, stop;
uint32_t val; uint32_t val;
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@ -44,6 +47,11 @@ void setup()
Serial.println("\nDone..."); Serial.println("\nDone...");
} }
void loop() void loop()
{ {
} }
// -- END OF FILE --

View File

@ -1,15 +1,18 @@
# Syntax Coloring Map For AnalogPin # Syntax Colouring Map For AnalogPin
# Datatypes (KEYWORD1) # Data types (KEYWORD1)
AnalogPin KEYWORD1 AnalogPin KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
setPrescaler KEYWORD2 setPrescaler KEYWORD2
getPrescaler KEYWORD2 getPrescaler KEYWORD2
setNoiseThreshold KEYWORD2 setNoiseThreshold KEYWORD2
getNoiseThreshold KEYWORD2 getNoiseThreshold KEYWORD2
setSmoothWeight KEYWORD2 setSmoothWeight KEYWORD2
getSmoothWeight KEYWORD2 getSmoothWeight KEYWORD2
read KEYWORD2 read KEYWORD2
readSmoothed KEYWORD2 readSmoothed KEYWORD2
readPrevious KEYWORD2 readPrevious KEYWORD2

View File

@ -15,8 +15,9 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/AnalogPin" "url": "https://github.com/RobTillaart/AnalogPin"
}, },
"version": "0.2.5", "version": "0.2.6",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*",
"headers": "AnalogPin.h"
} }

View File

@ -1,5 +1,5 @@
name=AnalogPin name=AnalogPin
version=0.2.5 version=0.2.6
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for AnalogPin sentence=Arduino Library for AnalogPin

View File

@ -29,6 +29,7 @@ unittest_setup()
{ {
} }
unittest_teardown() unittest_teardown()
{ {
} }
@ -36,6 +37,8 @@ unittest_teardown()
unittest(test_constructor) unittest(test_constructor)
{ {
fprintf(stderr, "ANALOGPIN_LIB_VERSION: %s\n", (char *) ANALOGPIN_LIB_VERSION);
AnalogPin AP(0); // A0 not supported AnalogPin AP(0); // A0 not supported
assertEqual(7, AP.getPrescaler()); assertEqual(7, AP.getPrescaler());
@ -65,6 +68,7 @@ unittest(test_prescaler)
} }
} }
unittest(test_noiseThreshold) unittest(test_noiseThreshold)
{ {
AnalogPin AP(0); AnalogPin AP(0);
@ -76,6 +80,7 @@ unittest(test_noiseThreshold)
} }
} }
unittest(test_smooth) unittest(test_smooth)
{ {
AnalogPin AP(0); AnalogPin AP(0);
@ -87,6 +92,7 @@ unittest(test_smooth)
} }
} }
unittest(test_read) unittest(test_read)
{ {
AnalogPin AP(0); AnalogPin AP(0);