AnalogIn
An analog (ie. continuous) input unit that returns values between 0 and 1 (ie. 0% and 100%).
The unit is assigned to a specific pin
on the board.
The mode
specifies the behavior of the component attached to the pin:
in
DIRECT
mode (default) the value is expressed as a percentage of the reference voltage (Vref, typically 5V)in
INVERTED
mode the value is inverted (ie. 0V corresponds to 100% while 2.5V corresponds to 50%).
Example
Control an LED using a potentiometer.
#include <Plaquette.h>
AnalogIn potentiometer(A0);
AnalogOut led(9);
SineOsc oscillator;
void begin() {}
void step() {
// The analog input controls the frequency of the LED's oscillation.
oscillator.frequency(potentiometer.mapTo(2.0, 10.0));
oscillator >> led;
}
Reference
-
class AnalogIn : public Node, public PinUnit, public Smoothable
A generic class representing a simple analog input.
Public Functions
-
AnalogIn(uint8_t pin, uint8_t mode = DIRECT)
Constructor.
- Parameters:
pin – the pin number
mode – the mode (DIRECT or INVERTED)
-
inline virtual float get()
Returns value in [0, 1].
-
virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
-
inline uint8_t pin() const
Returns the pin this component is attached to.
-
inline uint8_t mode() const
Returns the mode of the component.
-
inline virtual void mode(uint8_t mode)
Changes the mode of the component.
-
inline virtual void smooth(float smoothTime = PLAQUETTE_DEFAULT_SMOOTH_WINDOW)
Apply smoothing to object.
-
inline virtual void noSmooth()
Remove smoothing.
-
inline virtual void cutoff(float hz)
Changes the smoothing window cutoff frequency (expressed in Hz).
-
inline float cutoff() const
Returns the smoothing window cutoff frequency (expressed in Hz).
-
AnalogIn(uint8_t pin, uint8_t mode = DIRECT)
Warning
If the analog input pin is not connected to anything, the value returned by get()
will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).