# Booleans help

why doesn’t the right intake work when I only hit R1? It just doesn’t move

Maybe, don’t make a new thread for every problem you have. How about you delete this thread (if you can) and just ask your questions in the other thread.

1 Like

you’re telling the right intake to spin when you press r1, but later in the code you tell the right intake to stop spinning unless both l1 and r1 are pressed.

so the motor does try to spin, but later in the code you tell it to stop. So the end result is that it doesn’t move.

1 Like

How could I fix this?

you need to think about the logic of your if statements. you want the right intake to spin forwards when you press R1, you want it to spin backwards when you press R2, and you want it to spin backwards when you press L1 and R1.

so only tell it to stop when you aren’t pressing any of those combinations.

if R1 is pressed and L1 isn’t, then spin forwards.
if R2 is pressed or both L1 and R1 pressed then spin in reverse
otherwise stop.

1 Like

I want both the left and right intake to spin forward when R1 is pressed, and backward when R2 is pressed. But when R1 and L1 are both pressed the left intake spins forward while the right intake spins backward

I was just talking about in terms of the right motor.

It’s easier to understand the necessary logic when you take each motor at a time, and think about how you want it to behave under different circumstances. you can do the same thing with all your motors to make sure your if statements are actually doing what you want them to do.

5 Likes

This was using ROBOTC, but the same principles apply. You must only set a motor once in the while loop (generally speaking, I’m sure there are some exceptions)

5 Likes

your parentheses are off. you should have something like this

``````if (Mars.ButtonL1.pressing() && Mars.ButtonR1.pressing()) {}
``````
5 Likes

you have a `(` when you don’t need one. the code has highlighted it for you, just delete it.
you also have an extra `)` in front.

1 Like

Thank you so much, I was overthinking it. happens a lot

What text editor are you using?

If it’s VSCode, I would HIGHLY recommend this extension:
It makes all braces easier to see!

3 Likes

I’m using VEXcode Pro

1 Like

Are you surrounding your code with a forever loop? -> while(true){}

Because if you are not, then it will never happen, because of how C++ works.

EDIT: Never mind I double checked your code and saw that an answer worked for you already.

Good luck!

1 Like

First off, instead of posting a screenshot please copy and paste your code into this forum and then surround it with the code syntax highlighting formatting. This allows people to easily manipulate the code without having to retype it. The syntax highlighting is not a well documented feature but it’s the same as Slack and other platforms (ignore the hotkeys, just use the backtick symbol):

Now for your code.

What it says right now is…

Go get on a treadmill and start running (the outer while loop I am presuming exists).

If a 1 appears on the treadmill screen, spin your arms forward like you just don’t care, else if a 2 appears on the treadmill screen, spin the arms backwards, else don’t spin your arms.

AFTER THAT, if both 1 and 2 are on the screen spin the arms backwards else stop.

It’s worth noting that this logic is flawed as anything other than both 1 and 2 will trigger the second else clause and since the CPU can execute that code much faster than the motor can react, you will probably only see the motor spin when you have both 1 and 2 pressed.

All you need is to combine the if-elses.

``````// In case this isn't clear and since people on here
// like to be pedantic with me, this is pseudocode
if(B1 and B2) {
// Ball filter, spin right rev
} else if(B1) {
// spin fwd
} else if(B2) {
// spin rev
} else {
// stop
}
``````
2 Likes