help programming potentiometer

hey i had a question can you guys please help me with code for pontentiometer using void statements for the mobile goal intake

i asked my friends who also do programming they said i have to have two statements in while loop i didnt really get it much.

this what i have right now

#pragma config(Sensor, in1, pontmojo, sensorPotentiometer)
#pragma config(Motor, port1, mojo1, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, mojo2, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

void mojo(int angle, int speed) {
motor[mojo1] = speed;
motor[mojo2] = speed;
while(SensorValue[pontmojo] < angle) {
//…wait…and wait…
wait1Msec(15);
}
motor[mojo1] = 0;
motor[mojo2] = 0;
}

task main()
{
mojo(1500, 127);
wait1Msec(2000);
mojo(1500, -127);
}

will this work or not

thanks

I think he’s talking about your main loop. With comments:

main {
   // run mojo to angle 1500 at +127 power
  mojo(1500, 127);
   
   wait1Msec(2000);

   // run mojo to angle 1500 at -127 power
   mojo(1500, -127);
}

When you post your code, please select all of it with your cursor, and then click the button in the toolbar that looks like < /> (to the left of “Preview” checkbox). People will generally be more inclined to help you if they can actually read your code here in the forum instead of having to copy & paste it into an editor.

That seems like it should work, however, I would suggest replacing this section:

while(SensorValue[pontmojo] < angle) {
//…wait…and wait…
wait1Msec(15);
}

with a simple

waitUntil((SensorValue[pontmojo] > angle)

It’s a far more concise and possibly more reliable way of doing that.

so how would you use void statements for this

sorry for asking stupid questions i am still new to programming


#pragma config(Sensor, in1,    pontmojo,       sensorPotentiometer)
#pragma config(Motor,  port1,           mojo1,         tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           mojo2,         tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

void mojo(int angle, int speed) {
    motor[mojo1] = speed;
     motor[mojo2] = speed;
    while(SensorValue[pontmojo] < angle) {
        //...wait...and wait...
    }
    motor[mojo1] = 0;
     motor[mojo2] = 0;
}

task main()
{
mojo(1500, 127);
wait1Msec(2000);
mojo(1500, -127);
}

here it is with the thing

It’s difficult to answer, because I don’t know what you’re asking.

First, “void statements” aren’t a thing.

If you’re trying to ask “how do I write a user-defined function” you already have one in the code.

mojo() is a function. It doesn’t return anything, so you (or whoever) declared it to be of type “void”. If it had returned a value, it would have been declared as the type of value it returns; int, float, char, etc.

So, as I said, I don’t know what you’re asking. The only guess I have about what you might mean you already seem to know how to do. If you can explain a bit about what you want to accomplish, we can probably offer more help.

Your code looks like it won’t give any errors, but I would check the angles that you are putting into your function. The best way to find what potentiometer values you want is to use the debugger and read what values your potentiometer is at for different positions of your mobile goal intake.