You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ResponsiveAnalogRead is an Arduino library for eliminating noise in analogRead inputs without decreasing responsiveness. It sets out to achieve the following:
5
4
6
5
1. Be able to reduce large amounts of noise when reading a signal. So if a voltage is unchanging aside from noise, the values returned should never change due to noise alone.
7
6
2. Be extremely responsive (i.e. not sluggish) when the voltage changes quickly.
8
-
3. Have the option to be responsive when a voltage *stops* changing - when enabled the values returned must stop changing almost immediately after.
7
+
3. Have the option to be responsive when a voltage *stops* changing - when enabled the values returned must stop changing almost immediately after. When this option is enabled, a very small sacrifice in accuracy is permitted.
9
8
4. The returned values must avoid 'jumping' up several numbers at once, especially when the input signal changes very slowly. It's better to transition smoothly as long as that smooth transition is short.
10
9
11
-
You can preview the way the algorithm works with [sleep enabled](http://codepen.io/dxinteractive/pen/KzGegy) (minimising the time spend transitioning between values) and with [sleep disabled](http://codepen.io/dxinteractive/pen/ezdJxL) (transitioning responsively but smooth).
10
+
You can preview the way the algorithm works with [sleep enabled](http://codepen.io/dxinteractive/pen/zBEbpP) (minimising the time spend transitioning between values) and with [sleep disabled](http://codepen.io/dxinteractive/pen/ezdJxL) (transitioning responsively and accurately but smooth).
12
11
13
12
An article discussing the design of the algorithm can be found [here](http://damienclarke.me/code/posts/writing-a-better-noise-reducing-analogread).
14
13
15
-
###Impending version bump
16
-
Written 14/07/2016
17
-
18
-
Improvements to the sleep algorithm will be pushed as a minor version upgrade soon. Special thanks to /u/brontide for the assistance.
19
-
20
14
##How to install
21
15
22
16
In the Arduino IDE, go to Sketch > Include libraries > Manage libraries, and search for ResponsiveAnalogInput.
@@ -38,7 +32,7 @@ const int ANALOG_PIN = A0;
38
32
39
33
// make a ResponsiveAnalogRead object, pass in the pin, and either true or false depending on if you want sleep enabled
40
34
// enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly,
41
-
// where as disabling sleep will cause values to ease into their correct position smoothly
35
+
// where as disabling sleep will cause values to ease into their correct position smoothly and with slightly greater accuracy
42
36
ResponsiveAnalogRead analog(ANALOG_PIN, true);
43
37
44
38
// the next optional argument is snapMultiplier, which is set to 0.01 by default
@@ -81,6 +75,8 @@ void loop() {
81
75
-`int getRawValue() // get the raw analogRead() value from last update`
82
76
-`bool hasChanged() // returns true if the responsive value has changed during the last update`
83
77
-`void update(); // updates the value by performing an analogRead() and calculating a responsive value based off it`
78
+
-`void update(int rawValue); // updates the value by accepting a raw value and calculating a responsive value based off it (version 1.1.0+)`
79
+
-`bool isSleeping() // returns true if the algorithm is in sleep mode (version 1.1.0+)`
84
80
85
81
##Other methods (settings)
86
82
@@ -98,9 +94,7 @@ Sleep allows you to minimise the amount of responsive value changes over time. I
98
94
99
95
It's behaviour can be modified with the following methods:
100
96
-`void enableEdgeSnap() // edge snap ensures that values at the edges of the spectrum (0 and 1023) can be easily reached when sleep is enabled`
101
-
-`void setSleepDelay(unsigned int ms) // sets the amount of time before sleeping`
102
-
-`void setSleepActivityThreshold(unsigned int newThreshold) // the amount of movement that must take place while asleep for it to register as activity and start moving the output value. Defaults to 20.`
103
-
-`void setAwakeActivityThreshold(unsigned int newThreshold) // the amount of movement that must take place while awake for it to register as activity, and reset the timer before sleep occurs. Defaults to 5.`
97
+
-`void setActivityThreshold(float newThreshold) // the amount of movement that must take place for it to register as activity and start moving the output value. Defaults to 4.0. (version 1.1+)`
104
98
105
99
###Snap multiplier
106
100
@@ -109,8 +103,18 @@ It's behaviour can be modified with the following methods:
109
103
SnapMultiplier is a value from 0 to 1 that controls the amount of easing. Increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive, but doing so may cause more noise to seep through when sleep is not enabled.
110
104
111
105
###Analog resolution
112
-
-`void setAnalogResolution(unsigned int resolution)`
106
+
-`void setAnalogResolution(int resolution)`
113
107
114
108
If your ADC is something other than 10bit (1024), set that using this.
115
109
116
-
Damien Clarke, 2016
110
+
## License
111
+
112
+
Licensed under the MIT License (MIT)
113
+
114
+
Copyright (c) 2016, Damien Clarke
115
+
116
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
117
+
118
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
119
+
120
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0 commit comments