Analog Inputs

#include "VMXPi.h"
int main(int argc, char *argv[])
{
bool realtime = false;
uint8_t update_rate_hz = 50;
VMXPi vmx(realtime, update_rate_hz);
if(vmx.IsOpen()) {
float full_scale_voltage;
if(vmx.io.Accumulator_GetFullScaleVoltage(full_scale_voltage)) {
printf("Analog Input Voltage: %0.1f\n", full_scale_voltage);
}
/* CONFIGURE ANALOG ACCUMULATOR RESOURCES */
VMXErrorCode vmxerr;
VMXChannelIndex first_anin_channel;
uint8_t num_analog_inputs = vmx.io.GetNumChannelsByType(VMXChannelType::AnalogIn, first_anin_channel);
VMXResourceHandle accumulator_res_handles[4];
for ( uint8_t analog_in_chan_index = first_anin_channel; analog_in_chan_index < first_anin_channel + num_analog_inputs; analog_in_chan_index++) {
VMXResourceIndex accum_res_index = analog_in_chan_index - first_anin_channel;
AccumulatorConfig accum_config;
if (vmx.io.ActivateSinglechannelResource(analog_in_chan_index, VMXChannelCapability::AccumulatorInput,
accumulator_res_handles[accum_res_index], &accum_config, &vmxerr)) {
printf("Analog Input Channel %d activated on Resource type %d, index %d\n", analog_in_chan_index,
EXTRACT_VMX_RESOURCE_TYPE(accumulator_res_handles[accum_res_index]),
EXTRACT_VMX_RESOURCE_INDEX(accumulator_res_handles[accum_res_index]));
}
}
for ( int i = 0; i < 50; i++) {
/* Display Analog Input Values */
for (int j = 0; j < num_analog_inputs; j++){
float an_in_voltage;
if(vmx.io.Accumulator_GetAverageVoltage(accumulator_res_handles[j], an_in_voltage, &vmxerr)){
printf("Analog In Channel %d Voltage: %0.3f\n", j, an_in_voltage);
}
}
vmx.time.DelayMilliseconds(10);
}
}
}