pros::adi::AnalogOut class

Constructors, destructors, conversion operators

AnalogOut(std::uint8_t adi_port) explicit
Configures an ADI port to act as an Analog Output.
AnalogOut(ext_adi_port_pair_t port_pair) explicit
Configures an ADI port on an adi_expander to act as an Analog Output.

Public functions

std::int32_t set_value(std::int32_t value) const
Sets the output for the Analog Output from 0 (0V) to 4095 (5V).
ext_adi_port_tuple_t get_port() const
Gets the port of the sensor.

Friends

std::ostream& operator<<(std::ostream& os, pros::adi::AnalogOut& analog_out)
This is the overload for the << operator for printing to streams.

Function documentation

std::int32_t pros::adi::AnalogOut::set_value(std::int32_t value) const

Sets the output for the Analog Output from 0 (0V) to 4095 (5V).

Parameters
value The value to set the ADI port to
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Inherited from ADIPort::set_value.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the ADI.

Example

#define ANALOG_SENSOR_PORT 1

void opcontrol() {
  pros::AnalogOut sensor (ANALOG_SENSOR_PORT);
  sensor.set_value(4095); // Set the port to 5V
}

ext_adi_port_tuple_t pros::adi::AnalogOut::get_port() const

Gets the port of the sensor.

Returns returns a tuple of integer ports.

Example

#define DIGITAL_SENSOR_PORT 1 // 'A'

void initialize() {
  pros::adi::AnalogIn sensor (DIGITAL_SENSOR_PORT);
  
     // Getting values from the tuple using std::get<index> 
     int sensorSmartPort = std::get<0>(sensor.get_port()); // First value
  int sensorAdiPort = std::get<1>(sensor.get_port()); // Second value

     // Prints the first and second value from the port tuple (The Adi Port. The first value is the Smart Port)
  printf("Sensor Smart Port: %d\n", sensorSmartPort);
  printf("Sensor Adi Port: %d\n", sensorAdiPort);   
}