Motor Rotation Code Help

So I have this code here:
while(LiftMotor.rotation(<2) &! LiftUpperLimit.pressing()){
which I want to use the v5 motor encoders to control a while loop, but am not sure how to use the encoder rotation number as a variable and use it count as a boolean 1 for the while statement while it is less than 2. How do I use the rotations as a variable?

First the syntax here is entirely incorrect. More proper code would be

while((LiftMotor.rotation(deg) < 2) && (LiftUpperLimit.pressing() == false)){}

I am not sure if your problem is that the code doesn’t work or if you just need to know how to do what you are asking. The comparison of the rotation of the LiftMotor will return true or false in the while statement which will help determine if the code in the while loop runs. As long as the rotation is less than 2 and the limit is not pressed the code in the while will run. Hopefully this is what you are looking for.

1 Like

Yeah my syntax… Isn’t the best. Thanks for the info, that solves my question. But, I have been running code similar to it and it has been working just fine. (vexcode) Is this just “messy but functional” code or…? And is that && you swapped out for my &! the same thing? &! has been working for me just fine so far I think.

EDIT: Ignore the last question about &&, I see that you reversed the limit switch with the “false.”

Here’s my program that works just fine:

if(Controller1.ButtonDown.pressing() &! LiftLowerLimit.pressing()){

Well I mean if it works… …It works! I did not know that &! was an operator in C++ and I still can’t find anything that says it but… If it works for you than it works. Glad you could get your code to work.

I just said work 5 times man.

It’s actually two operators: & and !. There is no guarantee that the result of A&!B will be the same as A && !B unless A and B are both boolean values, which he coincidentally has.


Yup. Six times actually. Thanks guys.

This is my strategy for tower takeover

Well, here is mine.