mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.6 AnalogPin
This commit is contained in:
parent
88af89a113
commit
909bcdb0c4
@ -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 --
|
||||
|
||||
|
@ -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 --
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
-
|
||||
|
||||
|
||||
|
@ -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 --
|
||||
|
||||
|
@ -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 --
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AnalogPin
|
||||
version=0.2.5
|
||||
version=0.2.6
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for AnalogPin
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user