How to read and use the Analog Input from Roborio

I am currently the assistant programmer for team 4665 and am having trouble reading the analog inputs from our Roborio. Currently I am using a PixyCam 2 to output a analog signal ranging from
0v to 3.3v, but cannot seem to import the value into my java code. I will post the code in a pastebin below. So far I have tried to import the function but am not seeing any results when attempting to turn a motor with the code using a Spark.
The last thing that would be nice is for a way to output to console showing the value of Analog(0)
Any help would be appreciated!



You probably want to use getAverageVoltage() in your code rather than a raw sample from it.

If you want to see the number get used to using SmartDashboard. It has some great widgets in there where you can plot a number over time if you’re looking to see the analog voltage changes under the right conditions.

SmartDashboard.putNumber("AI Voltage", ai.getAverageVoltage());

If you put that function in one of the periodic methods (autonomous or teleop) you’ll be able to see the voltage value as it’s coming in from the sensor.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.