I want to add the CP5 button into my state machine but I don't know how to remove the mousePressed function and instead make the button change the states. Please help!
import controlP5.*;
ControlP5 cp5;
int state = 0;
void setup() {
size(600, 600);
background(0);
cp5 = new ControlP5(this);
cp5.addButton("colorA");
}
void draw() {
//state machine
if (state == 0) {
noStroke();
fill(0, 255, 0);
rect(0, 0, 600, 600);
}
if (state == 1) {
noStroke();
fill(255, 0, 0);
rect(0, 0, 600, 600);
}
if (state == 2) {
noStroke();
fill(0, 0, 255);
rect(0, 0, 600, 600);
}
if (state == 3) {
noStroke();
fill(128, 3, 255);
rect(0, 0, 600, 600);
}
if (state == 4) {
noStroke();
fill(3, 249, 255);
rect(0, 0, 600, 600);
}
if (state == 5) {
noStroke();
fill(254, 255, 3);
rect(0, 0, 600, 600);
}
}
void mousePressed() {
state ++;
if (state > 5) state = 1;
}