|
Stepdance Software Library
|
AnalogInput components read values from physical user interface components and enable them to be mapped to Stepdance Components. More...
#include <analog_in.hpp>
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. | |
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:
| 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.
| pin_reference | Index of the physical analog input pin (e.g. IO_A1, IO_A2, IO_A3, IO_A4). |
| 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.).
| target_parameter | Pointer to the ControlParameter to map to. |
| ControlParameter AnalogInput::read | ( | ) |
Reads the last converted and scaled value from the Analog Input.
| ControlParameter AnalogInput::read_raw | ( | ) |
Reads the last raw ADC value from the Analog Input.
| void AnalogInput::set_callback | ( | void(* | callback_function )() | ) |
Sets a callback function that will be called each time a new analog value is read.
| callback_function | Pointer 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() {
// Do something with inputValue, e.g., print it to the console
Serial.println(inputValue);
}
void loop(){
dance_loop();
}
|
| 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.
| output_at_ceiling | ControlParameter value corresponding to scaled output value at the upper limit. |
| 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.
| output_at_ceiling | ControlParameter value corresponding to scaled output value at the upper limit. |
| adc_upper_limit | Raw ADC value corresponding to the upper limit. |
| void AnalogInput::set_floor | ( | ControlParameter | output_at_floor | ) |
Sets the scaled output value of the Analog Input at the floor (lower limit).
| output_at_floor | ControlParameter value corresponding to scaled output value at the lower limit. |
| 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.
| output_at_floor | ControlParameter value corresponding to scaled output value at the lower limit. |
| adc_lower_limit | Raw ADC value corresponding to the lower limit. |