Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QuantizedPot Class Reference

#include <QuantizedPot.h>

Public Member Functions

 QuantizedPot (const uint8_t pin, int8_t maxRanges)
 
 ~QuantizedPot ()
 
int8_t addRange (int start, int end)
 
void begin (uint8_t threshold=AbstractDebouncedButton::DefaultThreshold, uint8_t delay=AbstractDebouncedButton::DefaultButtonDelay)
 
void update ()
 
int8_t value ()
 
int velocity ()
 

Protected Member Functions

int8_t _value ()
 
void setState (int8_t newState)
 

Protected Attributes

const uint8_t _pin
 
int8_t _rangeMax
 
int8_t _rangeCount
 
NumericRange< int > ** _ranges
 
uint8_t _threshold
 
uint8_t _delay
 
uint32_t _lastUpdate
 
uint8_t _counter
 
int8_t _state
 
uint32_t _lastStateChange
 
int _lastRaw
 
int _velocity
 

Detailed Description

Use potential divider to select values based on specified ranges.

Definition at line 10 of file QuantizedPot.h.

Constructor & Destructor Documentation

◆ QuantizedPot()

QuantizedPot::QuantizedPot ( const uint8_t  pin,
int8_t  maxRanges 
)

Constructor.

Parameters
pinthe analog input pin to monitor (e.g. A0)
maxRangesthe maximum number of ranges we will want in our object

Definition at line 7 of file QuantizedPot.cpp.

◆ ~QuantizedPot()

QuantizedPot::~QuantizedPot ( )

Destroctor

de-allocates ranges

Definition at line 22 of file QuantizedPot.cpp.

Member Function Documentation

◆ _value()

int8_t QuantizedPot::_value ( )
protected

Instantaneous value.

Returns
the index of the range the analog pin value is in at this instant.

Definition at line 78 of file QuantizedPot.cpp.

Here is the caller graph for this function:

◆ addRange()

int8_t QuantizedPot::addRange ( int  start,
int  end 
)

Add a range to the object. Cannot add more than maxRanges (from constructor)

Parameters
startthe first valid number of the range
endthe last valid number of the range (not inclusive)
Returns
the index of the range in the object, or -1 if the range could not be added

Definition at line 36 of file QuantizedPot.cpp.

◆ begin()

void QuantizedPot::begin ( uint8_t  threshold = AbstractDebouncedButton::DefaultThreshold,
uint8_t  delay = AbstractDebouncedButton::DefaultButtonDelay 
)

Initializtion.

Parameters
thresholddebouncing threshold (see DebouncedButton for details)
delaydebouncing delay (see DebouncedButton for details)

Definition at line 50 of file QuantizedPot.cpp.

◆ update()

void QuantizedPot::update ( )

Allocate Timeslice.

This method must be called frequently - usually from loop()

Definition at line 58 of file QuantizedPot.cpp.

Here is the call graph for this function:

◆ value()

int8_t QuantizedPot::value ( )

Get value.

Returns
Index of range presently selected, or -1 if no range selected. if more than once range is valid (overlapping ranges), the lowest index which is valid will be returned.

Definition at line 73 of file QuantizedPot.cpp.

◆ velocity()

int QuantizedPot::velocity ( )
inline

Get velocity

How far the current measurement is from the last measurement

Definition at line 59 of file QuantizedPot.h.


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