mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.2.7 AnalogPin
This commit is contained in:
parent
5a23134dbd
commit
82f3168874
@ -1,3 +1,18 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
@ -8,4 +23,6 @@ compile:
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
||||
|
@ -1,23 +1,12 @@
|
||||
//
|
||||
// FILE: AnalogPin.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.6
|
||||
// VERSION: 0.2.7
|
||||
// DATE: 2013-09-09
|
||||
// PURPOSE: wrapper for analogRead with smoothing and noise filtering
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.00 2013-09-09 initial version
|
||||
// 0.1.01 2013-11-09 added some comments
|
||||
// 0.1.02 2014-10-05 changed signatures data types
|
||||
// 0.1.03 2014-12-07 some refactor
|
||||
// 0.1.04 2015-03-06 refactor smaller footprint
|
||||
// 0.2.00 2015-05-14 added pre-scale support
|
||||
// 0.2.01 2015-12-19 breaking interface; big refactor;
|
||||
// 0.2.2 2020-03-25 refactor AVR specific code; bugfix
|
||||
// 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.
|
||||
// HISTORY: see changelog
|
||||
|
||||
|
||||
|
||||
#include "AnalogPin.h"
|
||||
@ -36,9 +25,9 @@ AnalogPin::AnalogPin(const uint8_t pin)
|
||||
|
||||
void AnalogPin::setPrescaler(const uint8_t prescale)
|
||||
{
|
||||
_prescale = prescale;
|
||||
if (_prescale < 2) _prescale = 2;
|
||||
else if (_prescale > 7) _prescale = 7;
|
||||
_prescale = prescale;
|
||||
if (_prescale < 2) _prescale = 2;
|
||||
else if (_prescale > 7) _prescale = 7;
|
||||
};
|
||||
|
||||
|
||||
@ -76,7 +65,7 @@ int AnalogPin::readSmoothed()
|
||||
void AnalogPin::_rawRead()
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
// remember old register value
|
||||
// remember old register value
|
||||
uint8_t ADCSRA_TMP = ADCSRA;
|
||||
ADCSRA = (ADCSRA | 0x07) & (0xF8 | _prescale);
|
||||
#elif defined(ARDUINO_ARCH_SAM)
|
||||
@ -88,7 +77,7 @@ void AnalogPin::_rawRead()
|
||||
_value = analogRead(_pin);
|
||||
|
||||
#if defined(ARDUINO_ARCH_AVR)
|
||||
// restore register
|
||||
// restore register
|
||||
ADCSRA = ADCSRA_TMP;
|
||||
#elif defined(ARDUINO_ARCH_SAM)
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: AnalogPin.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.6
|
||||
// VERSION: 0.2.7
|
||||
// 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.6"))
|
||||
#define ANALOGPIN_LIB_VERSION (F("0.2.7"))
|
||||
|
||||
|
||||
class AnalogPin
|
||||
@ -20,28 +20,28 @@ public:
|
||||
|
||||
explicit AnalogPin(const uint8_t pin);
|
||||
|
||||
// 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
|
||||
// 4 => 24 uSec 7 => 120 uSec (default/normal)
|
||||
// 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
|
||||
// 4 => 24 uSec 7 => 120 uSec (default/normal)
|
||||
void setPrescaler(const uint8_t prescale = 7);
|
||||
inline uint8_t getPrescaler(void) const { return _prescale; };
|
||||
|
||||
// noise 0..255; in practice only small values are used (0..10).
|
||||
// noise 0..255; in practice only small values are used (0..10).
|
||||
inline void setNoiseThreshold(const uint8_t noise = 0) { _noise = noise; };
|
||||
inline uint8_t getNoiseThreshold(void) const { return _noise; };
|
||||
|
||||
// alpha 0..31;
|
||||
|
||||
// alpha = 0..31;
|
||||
void setSmoothWeight(const uint8_t alpha = 0);
|
||||
inline uint8_t getSmoothWeight(void) const { return _alpha; };
|
||||
|
||||
// set twice to true to do analogRead twice to reduce noise too
|
||||
// twice=true to do analogRead twice to reduce noise
|
||||
int read(const bool twice = false);
|
||||
int readSmoothed();
|
||||
|
||||
// expose internal data as that might be useful.
|
||||
inline int readPrevious(void) const { return _prevValue; }
|
||||
// expose internal data as that might be useful.
|
||||
inline int readPrevious(void) const { return _prevValue; }
|
||||
inline int readLast(void) const { return _value; }
|
||||
|
||||
|
||||
|
53
libraries/AnalogPin/CHANGELOG.md
Normal file
53
libraries/AnalogPin/CHANGELOG.md
Normal file
@ -0,0 +1,53 @@
|
||||
# Change Log AnalogPin
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.2.7] - 2022-10-28
|
||||
- Add RP2040 support to build-CI.
|
||||
- Add CHANGELOG.md
|
||||
|
||||
## [0.2.6] - 2021-12-12
|
||||
- update library.json
|
||||
- update license
|
||||
- minor edits.
|
||||
|
||||
## [0.2.5] - 2021-10-17
|
||||
- update Arduino-CI
|
||||
|
||||
## [0.2.4] - 2020-12-10
|
||||
- add Arduino-CI
|
||||
|
||||
## [0.2.3] - 2020-05-27
|
||||
- update library.json
|
||||
|
||||
## [0.2.2] - 2020-03-25
|
||||
- refactor AVR specific code
|
||||
- bugfix
|
||||
|
||||
## [0.2.01] - 2015-12-19
|
||||
- breaking interface
|
||||
- big refactor
|
||||
|
||||
## [0.2.00] - 2015-05-14
|
||||
- added pre-scale support
|
||||
|
||||
----
|
||||
|
||||
## [0.1.04] - 2015-03-06
|
||||
- refactor smaller footprint
|
||||
|
||||
## [0.1.03] - 2014-12-07
|
||||
- some refactor
|
||||
|
||||
## [0.1.02] - 2014-10-05
|
||||
- changed signatures data types
|
||||
|
||||
## [0.1.01] - 2013-11-09
|
||||
- added some comments
|
||||
|
||||
## [0.1.00] - 2013-09-09
|
||||
- initial version
|
@ -20,7 +20,6 @@ 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.
|
||||
@ -75,6 +74,6 @@ This can be used to suppress noise too.
|
||||
- advantage of certain functions, when to use
|
||||
- more examples
|
||||
- **volts()** + get/setFactor(float f)
|
||||
-
|
||||
- move code to .cpp
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AnalogPin"
|
||||
},
|
||||
"version": "0.2.6",
|
||||
"version": "0.2.7",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AnalogPin
|
||||
version=0.2.6
|
||||
version=0.2.7
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for AnalogPin
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "ANALOGPIN_LIB_VERSION: %s\n", (char *) ANALOGPIN_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
@ -37,8 +38,6 @@ 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());
|
||||
|
Loading…
Reference in New Issue
Block a user