0
我似乎无法得到正确的后续代码。用于处理的开/关按钮
这是我用于Processing的基本程序。当我点击它时,我改变了方块的颜色,但是当我第二次点击时,我似乎无法让它再次改变。
它基本上是一个切换按钮,当我点击正方形而不是当我释放鼠标按钮时。我试图将它与Arduino集成,这就是为什么有端口写入。
boolean A = true;
int x = 50;
int y = 50;
int w = 100;
int h = 100;
import processing.serial.*;
Serial port;
int val;
void setup() {
size(200, 200);
noStroke();
fill(255, 0, 0);
rect(x, y, w, h);
port = new Serial(this, 9600);
}
void draw() {
background(255);
if ((A) && (mousePressed) && ((mouseX > x) && (mouseX < x + w) &&
(mouseY > y) && (mouseY < y + h))) { // If mouse is pressed,
fill(40, 80, 90);
A = !A;// change color and
port.write("H"); // Send an H to indicate mouse is over square.
}
rect(50, 50, 100, 100); // Draw a square.
}
工作就像一个魅力,感谢您的帮助! –