RSeries astromech firmware
AnalogMonitor Class Reference

#include <core/AnalogMonitor.h>

Detailed Description

Used for eliminating noise in analogRead inputs without decreasing responsiveness. It sets out to achieve the following:

  • 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.
  • Be extremely responsive (i.e. not sluggish) when the voltage changes quickly.
  • 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.
  • 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.
+ Inheritance diagram for AnalogMonitor:
+ Collaboration diagram for AnalogMonitor:

Public Member Functions

 AnalogMonitor ()
 Default Constructor. More...
 
 AnalogMonitor (byte pin, bool sleepEnable=true, float snapMultiplier=0.01)
 Constructor with explicit call to begin() More...
 
void begin (byte pin, bool sleepEnable=true, float snapMultiplier=0.01)
 Start reading data from analog port. More...
 
int getValue ()
 
int getRawValue ()
 
bool hasChanged ()
 
bool isSleeping ()
 
virtual void animate ()
 Subclasses must implement this function to run through a single frame of animation/activity. More...
 
void setSnapMultiplier (float newMultiplier)
 
void enableSleep ()
 
void disableSleep ()
 
void enableEdgeSnap ()
 
void disableEdgeSnap ()
 Edge snap ensures that values at the edges of the spectrum (0 and 1023) can be easily reached when sleep is enabled. More...
 
void setActivityThreshold (float newThreshold)
 
void setAnalogResolution (int resolution)
 The amount of movement that must take place to register as activity and start moving the output value. More...
 
- Public Member Functions inherited from AnimatedEvent
 AnimatedEvent ()
 Default Constructor. More...
 
void setLoopDoneCallback (AnimatedLoopDone loopProc)
 

Additional Inherited Members

- Static Public Member Functions inherited from AnimatedEvent
static void process ()
 Calls animate() for each created AnimatedEvent subclass. More...
 

Constructor & Destructor Documentation

◆ AnalogMonitor() [1/2]

AnalogMonitor::AnalogMonitor ( )
inline

Default Constructor.

Default constructor must be followed by a call to begin()

◆ AnalogMonitor() [2/2]

AnalogMonitor::AnalogMonitor ( byte  pin,
bool  sleepEnable = true,
float  snapMultiplier = 0.01 
)
inline

Constructor with explicit call to begin()

Parameters
pinthe pin to read
sleepEnableenabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly, where as disabling sleep will cause values to ease into their correct position smoothly
snapMultipliera 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 if sleep is not enabled
See also
begin(byte, bool, flooat)

Member Function Documentation

◆ animate()

virtual void AnalogMonitor::animate ( )
inlinevirtual

Subclasses must implement this function to run through a single frame of animation/activity.

Subclasses should not call delay() or otherwise block.

Implements AnimatedEvent.

◆ begin()

void AnalogMonitor::begin ( byte  pin,
bool  sleepEnable = true,
float  snapMultiplier = 0.01 
)
inline

Start reading data from analog port.

Parameters
pinthe pin to read
sleepEnableenabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly, where as disabling sleep will cause values to ease into their correct position smoothly
snapMultipliera 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 if sleep is not enabled

◆ disableEdgeSnap()

void AnalogMonitor::disableEdgeSnap ( )
inline

Edge snap ensures that values at the edges of the spectrum (0 and 1023) can be easily reached when sleep is enabled.

◆ disableSleep()

void AnalogMonitor::disableSleep ( )
inline

◆ enableEdgeSnap()

void AnalogMonitor::enableEdgeSnap ( )
inline

◆ enableSleep()

void AnalogMonitor::enableSleep ( )
inline

◆ getRawValue()

int AnalogMonitor::getRawValue ( )
inline
Returns
the raw analogRead() value from last update

◆ getValue()

int AnalogMonitor::getValue ( )
inline
Returns
the responsive value from last update

◆ hasChanged()

bool AnalogMonitor::hasChanged ( )
inline
Returns
true if the responsive value has changed during the last update

◆ isSleeping()

bool AnalogMonitor::isSleeping ( )
inline
Returns
true if the algorithm is currently in sleeping mode

◆ setActivityThreshold()

void AnalogMonitor::setActivityThreshold ( float  newThreshold)
inline

◆ setAnalogResolution()

void AnalogMonitor::setAnalogResolution ( int  resolution)
inline

The amount of movement that must take place to register as activity and start moving the output value.

Defaults to 4.0

◆ setSnapMultiplier()

void AnalogMonitor::setSnapMultiplier ( float  newMultiplier)
inline

The documentation for this class was generated from the following file: