Easy to use buttons code to add buttons on your robot brain

Link: Link To Code

I made this because bored.


Weedcat. Weedcat

To use just copy from like 13-89 into your code. Than use addButton(x, y, width, height, function that gets called when its pressed, text, color);

cool, ask any questions in the comment thing


Nice, thanks for sharing.

I’d add to your example on setting the button name

int main() {
  addButton(0, 0, 250, 100, onButtonPress);


int main() {
  addButton(0, 0, 250, 100, onButtonPress, "Clear");

since most people will want to name their button(s).


Thanks! I completely forgot. Also, you can change the color of the button

addButton(0, 0, 250, 100, onButtonPress, “Clear”, vex::color(255, 0, 0));


You might want to add at to your original post Robot Platform IQ/V5 and coding language so people know whether or not to download code.

Right now it is in ChitChat so not specific at all about the context.

Which category should i put it in?

V5 programming since that’s what you coded for. If I ask @Drow nicely to move it, he may retag it for you. Please?

This is great.

Could you use a constructor within the class instead of addButton ?

class ButtonPressable {

	int x;
	int y;
	int width;
	int height;
	std::string text = "Filler";
	ButtonPressable (int x, int y, int width, int height, void (*onPress)(), std::string text = "Filler", vex::color color = vex::color(255, 0, 0)) {
		x = x;
		y = y;
		width = width;
		height = height;
		onPress = onPress;

int main() {
  ButtonPressable(0, 0, 250, 100, onButtonPress, "Clear", vex::color(255, 0, 0));

When I get V5, I’m going to write a class for buttons.

I’m in IQ, so you can’t draw to the brain and it’s not a touchscreen. You can only print and check if Brain buttons are pressed. Like, physical Up, Down, and Check buttons.

So then I can just do something like

new Button(0, 0, 250, 100, [function to call when button pressed], "Name"); 
// Or however you create new objects in C++

Basically what you did, except using class instead of functions.

i didnt think of that, make a pull request maybe?