I am trying to program my VEX IQ robot to use the distance sensor to change the drivetrain and LED according to the following distances:
300mm - full speed ahead - LED to green
299mm-100mm - reduce motor speed to 50% and drive forward - LED to yellow
<99 - reduce motor power to 0% - LED to red
I programmed the brain to output the distance to the brain and when I program this using Modkit and run the program, the distance sensor reads all sorts of different numbers and therefore has the drivetrain randomly cycling through the commands. Does this sound like a defective sensor or interference with some other ultrasonic device? I will post my code below:
Any help would be greatly appreciated.