When I use this code, the liftstate goes right to 3 and then right back down to 0. I’m not sure how to fix this.
you have the && liftState < 3
inside the get_digital parameters, it should be outside. same for the other line
I fixed it but it does the same thing
In addition to what @iseau395 mentioned*, get_digital()
detects when a button is being held, so every time you run lift_func()
and are holding the button down, it will increment liftState
, causing it to immediately jump to 3. You should change it to get_digital_new_press()
instead.
*
I was originally going to write what they said in this response, but I saw their comment in the middle of writing this so I deleted it. I was curious what it would actually return though, so here is what I thought:
You are passing pros::E_CONTROLLER_DIGITAL_UP && liftState < 3
(which I am pretty sure would be evaluated as 10 && liftState < 3
since pros::E_CONTROLLER_DIGITAL_UP
is an enum with a value of 10, which, since non-zero numbers are evaluated as true in boolean expressions, would turn into liftState < 3
which is true (1) at the beginning of your code) as an input to get_digital()
, but since the controller_digital_e_t
enum is not defined for values under 6 I am not sure what this would return (probably 0, but then the liftState++
wouldn’t run, which doesn’t explain the behavior of your code (I am assuming you had probably just fixed this already and maybe used an old photo, and it was the get_digital()
that caused the behavior you described).