pros::adi::AnalogIn class

Derived classes

class Potentiometer

Constructors, destructors, conversion operators

AnalogIn(std::uint8_t adi_port) explicit
Configures an ADI port to act as an Analog Input.
AnalogIn(ext_adi_port_pair_t port_pair) explicit
Configures an ADI port to act as an Analog Input.

Public functions

std::int32_t calibrate() const
Calibrates the analog sensor on the specified port and returns the new calibration value.
std::int32_t get_value_calibrated() const
Gets the 12 bit calibrated value of an analog input port.
std::int32_t get_value_calibrated_HR() const
Gets the 16 bit calibrated value of an analog input port.
std::int32_t get_value() const
Reads an analog input channel and returns the 12-bit value.
ext_adi_port_tuple_t get_port() const
Gets the port of the sensor.

Friends

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

Function documentation

std::int32_t pros::adi::AnalogIn::get_value() const

Reads an analog input channel and returns the 12-bit value.

Returns The analog sensor value, where a value of 0 reflects an input voltage of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V

The value returned is undefined if the analog pin has been switched to a different mode. The meaning of the returned value varies depending on the sensor attached.

Inherited from ADIPort::get_value.

This function uses the following values of errno when an error state is reached: EADDRINUSE - The port is not configured as an analog input (e.g. the port has been reconfigured)

Example

#define ANALOG_SENSOR_PORT 1

void initialize() {
  pros::adi::AnalogIn sensor (ANALOG_SENSOR_PORT);
  std::cout << "Sensor Reading:" << sensor.get_value();
}

ext_adi_port_tuple_t pros::adi::AnalogIn::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);   
}