potentiometer/ analog inputs

We are having trouble getting our potentiometer code to work.

we declare it
AnalogInput *potemtiometer;

later
potentiometer = new AnalogInput(2);

and we can’t figure out the last part. We don’t have anything to go off of because last year was an easy 1,2,3 robot.

try using AnalogChannel instead of input

okay we’ll try that.

attempting analog channel didn’t work when we added

float anglesh = pot1.GetVoltage();

shouldn’t it be pot1->GetVoltage();?

i’m trying to make the code right and it compiles but we’ll see if i get something.

i haven’t actually had a potentiometer until now.

1075guy is right, because you declared it using a pointer you must use -> instead of .

use pot1->GetValue() for a 0-1023 range value, pot1->GetVoltage() for 0.0-5.0 range. Try both and see which one you like better

i try printing the values to the screen and i get really big values sometimes. Why would this be? is it because i might run the loops they are in too quuickly. i set them to .02 seconds and i think its doing better.

I actually disabled the watchdog for the autonomous because it won’t run through long waits in the system. this worked until just now when it started giving me watchdog not fed errors that have never happened before.

Perhaps there’s a digit or two left over on the screen from a previous print step? For example, if one value is 1003 and the next one is 996, it might end up on screen looking like 9963 if you aren’t careful.

this could be i will try to fix this.
would printing

printf(" =angletop");
printf("%d",angletop);

would this work in the correct format assuming it prints on line 1 and the %d writes over it?

no, this will output something like this:

         =angletop23         =angletop85         =angletop712         =angletop465         =angletop84         =angletop6         =angletop4586         =angletop589         =angletop486

i would recommend one printf a loop (if possible): printf("angletop=%d
",angletop);

we only need the number to print when autonomous is done. basically we have a 5 second waiting period where we find the values.

right now i just found out that the pot is mounted so up is down and down is up. so i’ll need to get someone to remount it.

Or you can correct it in software.


angletop = max - angletop;