Stepdance Software Library
Loading...
Searching...
No Matches
AnalogInput Class Reference

AnalogInput components read values from physical user interface components and enable them to be mapped to Stepdance Components. More...

#include <analog_in.hpp>

Inheritance diagram for AnalogInput:

Public Member Functions

 AnalogInput ()
 Default constructor for AnalogInput. Initializes an AnalogInput instance with default, unconfigured state. This does not configure hardware or register the input; call begin() to initialize hardware-specific settings and register the input with the system.
void begin (uint8_t pin_reference)
 Initialize the AnalogInput with a pin reference corresponding to the target physical analog input pin on the Stepdance Board.
void map (ControlParameter *target_parameter)
 Maps the AnalogInput to a ControlParameter, which will be updated each time a new analog value is read. ControlParameters are typically used to control Component parameters (e.g. 1DWaveGenerator Amplitude, VelocityGenerator Speed etc.).
void set_callback (void(*callback_function)())
 Sets a callback function that will be called each time a new analog value is read.
void set_floor (ControlParameter output_at_floor)
 Sets the scaled output value of the Analog Input at the floor (lower limit).
void set_floor (ControlParameter output_at_floor, uint16_t adc_lower_limit)
 Sets the scaled output value of the Analog Input at the floor (lower limit). This defines the mapping between raw ADC values and the output ControlParameter values.
void set_ceiling (ControlParameter output_at_ceiling)
 Sets the scaled output value of the Analog Input at the ceiling (upper limit). This defines the mapping between raw ADC values and the output ControlParameter values.
void set_ceiling (ControlParameter output_at_ceiling, uint16_t adc_upper_limit)
 Sets the scaled output value of the Analog Input at the ceiling (upper limit). This defines the mapping between raw ADC values and the output ControlParameter values.
void invert ()
 Inverts the output of the Analog Input, such that higher raw ADC values correspond to lower ControlParameter values and vice versa. Useful for inverting potentiometer or other analog UI elements without rewiring.
ControlParameter read ()
 Reads the last converted and scaled value from the Analog Input.
ControlParameter read_raw ()
 Reads the last raw ADC value from the Analog Input.

Detailed Description

AnalogInput components read values from physical user interface components and enable them to be mapped to Stepdance Components.

AnalogInputs function similarly to the Arduino analogIn function. They can be used to directly map analog readings from the Analog input terminals on the Machine Controller or Basic Module to Stepdance Component ControlParameters. Alternatively, you can read the value of the AnalogInput directly during the loop() function to implement custom control schemes. You can read AnalogInput values at either scaled values (based on user-defined floor and ceiling settings) or as raw Analog-to-Digital Converter (ADC) values.

Here's an example of how to instantiate and configure two AnalogInputs to either map to control parameters or read a value directly during the loop() function:

#define module_driver
#include "stepdance.hpp"
AnalogInput analog_a1;
AnalogInput analog_a2;
VelocityGenerator velocity_gen;
void setup() {
//analog input a1
analog_a1.set_floor(0, 25); //set floor to 0 output at ADC values of 25 and below.
analog_a1.set_ceiling(2.75, 1020); //set ceiling to 2.75 output at ADC values of 1020 and above.
analog_a1.map(&velocity_gen.speed_units_per_sec); //map analog output to VelocityGenerator speed ControlParameter
analog_a1.begin(IO_A1); //initialize analog input on physical input port IO_A1
//analog input a2
analog_a2.set_floor(0, 25);
analog_a2.set_ceiling(10, 1020);
analog_a2.begin(IO_A2);//initialize analog input on physical input port IO_A2
dance_start();
Serial.begin(115200);
}
void loop() {
float extrusionMultiplier = analog_a2.read(); //read analog input a2 value during loop and store it in variable
Serial.println(extrusionMultiplier); //print the read value to the serial console
dance_loop();
}

Member Function Documentation

◆ begin()

void AnalogInput::begin ( uint8_t pin_reference)

Initialize the AnalogInput with a pin reference corresponding to the target physical analog input pin on the Stepdance Board.

Parameters
pin_referenceIndex of the physical analog input pin (e.g. IO_A1, IO_A2, IO_A3, IO_A4).

◆ map()

void AnalogInput::map ( ControlParameter * target_parameter)

Maps the AnalogInput to a ControlParameter, which will be updated each time a new analog value is read. ControlParameters are typically used to control Component parameters (e.g. 1DWaveGenerator Amplitude, VelocityGenerator Speed etc.).

Parameters
target_parameterPointer to the ControlParameter to map to.

◆ read()

ControlParameter AnalogInput::read ( )

Reads the last converted and scaled value from the Analog Input.

Returns
The last read value, based on the internal conversion factor.

◆ read_raw()

ControlParameter AnalogInput::read_raw ( )

Reads the last raw ADC value from the Analog Input.

Returns
The last read raw ADC value.

◆ set_callback()

void AnalogInput::set_callback ( void(* callback_function )())

Sets a callback function that will be called each time a new analog value is read.

Parameters
callback_functionPointer to the callback function to be executed on new data. code example:
#define module_driver
#include "stepdance.hpp"
AnalogInput analog_a1;
void setup() {
//analog input a1
analog_a1.begin(IO_A1); //initialize analog input on physical input port IO_A1
analog_a1.set_callback(&analogInputCallback); //set the callback function to be called on new data
dance_start();
}
void analogInputCallback() {
float inputValue = analog_a1.read(); //read analog input a1 value during callback
// Do something with inputValue, e.g., print it to the console
Serial.println(inputValue);
}
void loop(){
dance_loop();
}

◆ set_ceiling() [1/2]

void AnalogInput::set_ceiling ( ControlParameter output_at_ceiling)

Sets the scaled output value of the Analog Input at the ceiling (upper limit). This defines the mapping between raw ADC values and the output ControlParameter values.

Parameters
output_at_ceilingControlParameter value corresponding to scaled output value at the upper limit.

◆ set_ceiling() [2/2]

void AnalogInput::set_ceiling ( ControlParameter output_at_ceiling,
uint16_t adc_upper_limit )

Sets the scaled output value of the Analog Input at the ceiling (upper limit). This defines the mapping between raw ADC values and the output ControlParameter values.

Parameters
output_at_ceilingControlParameter value corresponding to scaled output value at the upper limit.
adc_upper_limitRaw ADC value corresponding to the upper limit.

◆ set_floor() [1/2]

void AnalogInput::set_floor ( ControlParameter output_at_floor)

Sets the scaled output value of the Analog Input at the floor (lower limit).

Parameters
output_at_floorControlParameter value corresponding to scaled output value at the lower limit.

◆ set_floor() [2/2]

void AnalogInput::set_floor ( ControlParameter output_at_floor,
uint16_t adc_lower_limit )

Sets the scaled output value of the Analog Input at the floor (lower limit). This defines the mapping between raw ADC values and the output ControlParameter values.

Parameters
output_at_floorControlParameter value corresponding to scaled output value at the lower limit.
adc_lower_limitRaw ADC value corresponding to the lower limit.

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