How to use limit switch in auton selector?

So I’m trying to write a GUI in pros C++ using LLEMU to switch programs in my auton selector, kind of like in this video. Only difference is that I want to use 1 limit switch instead of 2. However, I have no idea what functions or keywords to use in order to utilize the limit switch input. Roughly, i plan to do something along the lines of
if(limit is pressed){//I don’t know what the technical way to state this is
limitCount = limitCount++;
followed by a switch statement corresponding to each of our programs
else {
switch(limitCount);//the same switch statement as above

and it’ll loop back to 1 after 5 increments. It would be really helpful if someone could let me know how this works. Thanks!

For graphics in PROS you have two options: LLEMU and LVGL


    Emulator for the old v4 LCD screen. It includes 3 buttons and a screen with a total of 8 lines available.
  • PROS' LLEMU tutorial


It sounds like LLEMU might be more your skill level, though you might be able to handle some simple LVGL code.

To code a limit switch you initialize it like this…

ADIButton limitSwitch('A');

Then to change a variable in the way you want you can code it like this…

int autonState = 0;
bool buttonUnpressed = true;

void initialize() {}
void disabled() {}
void competition_initialize()
        if(limitSwitch.isPressed() && buttonUnpressed)
            if(autonState == 5) autonState = 0;
            buttonUnpressed = false;
        if(!limitSwitch.isPressed()) buttonUnpressed = true;


The important thing here is the buttonUnpressed variable which is used to detect when the button is first pressed, thus doing an action once and requiring the button to be unpressed to before doing that thing again.

To display text to the screen using LLEMU you first initialize it like this…

void initialize()

Then write to the screen with something like this…

pros::c::lcd_print(0, "Current autonomous: %d", autonState);

All the function are available here.

If you have any other question feel free to ask.
Remember that pros has documentation and tutorials here.


Thank you for your answer! Considering this is an auton selector, would I need to put this in my initialize.cpp file, or would it be better to put it in a new file? Do I need to initialize the brain or do anything else before running the code? I seem to be getting error messages as it is now.

It is easiest to just put it into initialize.cpp. For “initialize the brain”, other than starting LLEMU (if that is what you are using) you don’t need to do anything else.

The error could be anything, so please post the error message for further assistance.

Also I forgot to mention that to access the variable autonState in autonomous.cpp add this line to the autonomous file…

extern int autonState;

This way the compiler knows that this file will be using and external variable called autonState.