Is there any way to pass a motor port or a sensor port as an object being input into a function as a parameter? Basically, I want to write just one “getEncoder” function, with one input parameter that is the encoder to be read. Can I do this?
Yes. Sensors are a special datatype called “tSensors”.
Here’s an example function:
void untilDark(int threshold = 505, tSensors sensorPort = in2)
{
while(SensorValue[sensorPort] < threshold){wait1Msec(1);}
}