pros::adi::DigitalOut class

Derived classes

class Pneumatics

Constructors, destructors, conversion operators

DigitalOut(std::uint8_t adi_port, bool init_state = LOW) explicit
Configures an ADI port to act as a Digital Output.
DigitalOut(ext_adi_port_pair_t port_pair, bool init_state = LOW) explicit
Configures an ADI port on an adi_expander to act as a Digital Output.

Public functions

std::int32_t set_value(std::int32_t value) const
Sets the digital value (1 or 0) of a pin.
ext_adi_port_tuple_t get_port() const
Gets the port of the sensor.

Friends

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

Function documentation

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

Sets the digital value (1 or 0) of a pin.

Parameters
value The value to set the ADI port to
Returns 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: EADDRINUSE - The port is not configured as a digital output (e.g. the port has been reconfigured)

Example

#define DIGITAL_SENSOR_PORT 1

void opcontrol() {
  bool state = LOW;
  pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT);
  while (true) {
    state != state;
    sensor.set_value(state);
    pros::delay(10); // toggle the sensor value every 50ms
  }
}

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