I have learned to code all of the controls for the robot, but I still need to learn to code some sensors. I’m starting off with potentiometers. I’m coding in C++ and my goal is to use a potentiometers value to make a motor turn until it is within a specific range of values. If you need any clarification on the question just ask! Thanks in advance!
You wrote Vex C++, so I’m using that. You can get the current pot value from pot.value(choose the unit type - I recommend degrees right now). Choose your target value. Then you can set up a PID loop or less to move things until the current value reaches the target value.
Pseudo code would read something like: “while potentiometer not in goal range, turn motor towards goal range”. The basic form will look something like
while(test) {motorcode;}
If you replace “test” with an appropriate logical test on your potentiometer value and “motorcode” with appropriate motor control code, you should be golden. Given that you’re checking a range of values with two endpoints, your test will include some combination of greater than (>), less than (<), OR (||), or AND (%%) operators, as you have to test your potentiometer against both end points.