Is it possible to make it so that when a button is pressed, it will change an int that you defined? From testing, it seems you can only make it perform a specific void, but not change the integer.
The button pressed function tells the program to call a specific function when the button is pressed. See the documentation here:
// create a function containing the code to run
void screenPressed( void ) {
int xPos = Brain.Screen.xPosition();
int yPos = Brain.Screen.yPosition();
Brain.Screen.setCursor(1,1);
Brain.Screen.clearLine();
Brain.Screen.print("Last press x: %04d, y: %04d", xPos, yPos);
Brain.Screen.setCursor(3,1);
Brain.Screen.clearLine();
Brain.Screen.print("Current state: Pressed");
}
void screenReleased( void ) {
int xPos = Brain.Screen.xPosition();
int yPos = Brain.Screen.yPosition();
Brain.Screen.setCursor(2,1);
Brain.Screen.clearLine();
Brain.Screen.print("Last release x: %04d, y: %04d", xPos, yPos);
Brain.Screen.setCursor(3,1);
Brain.Screen.clearLine();
Brain.Screen.print("Current state: Released");
}
int main() {
// tell the program what code to run when the screen is pressed
Brain.Screen.pressed(screenPressed);
// tell the program what code to run when the screen is released
Brain.Screen.released(screenReleased);
//Prevent main from exiting with an infinite loop.
while(1) {
task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
}
That is specifically for the screen pressed, but it works the same way as the button pressed. Any values you will need to have updated as the result of a button press would go in the functions specified by the pressed call. It would typically be used with the released function to do something when the button is released as well.
If you just want to check if the button is pressed, you should use the pressing function, which returns true if the button is currently being pushed.