Can we do for one button? If fan is active, button is green. If fan is inactive, button is red…
You know codes. How can we do it?
Yes, we can.
This stays the same.
if (fanIsActive)
fill(255, 0, 0);
else
fill(0, 245, 0);
ellipse(1870, 974, 15, 15);
Kill one button, the upper one of the two.
The remaining button is something like:
if (mouseX >= buttonJ_x && mouseX <= buttonJ_x + buttonJ_width &&
mouseY >= buttonJ_y && mouseY <= buttonJ_y + buttonJ_height) {
// toggle
if(fanIsActive) {
// it's active, we want to deactivate
buttonJ_clicked = true;
fill(0, 255, 0);
ellipse(1870, 974, 15, 15);
fanIsActive=false; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
myStepMotor.write("9");
}
else
{
// it's NOT active, we want to activate
buttonJ_clicked = true;
fill(0, 255, 0);
ellipse(1870, 974, 15, 15);
fanIsActive=true; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
myStepMotor.write("8"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
} else {
buttonJ_clicked = false;
}
2 Likes
Thanks, I will try it
1 Like
you remember, i give you a code for a toggle button here
1 Like
Thanks for helping buddy but @Chrisir solved my problem…
Thanks for everyone…
1 Like