私は次のコードを正しく取得できないようです。処理のON/OFFボタン
これは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.
}
チャームのように働いてくれてありがとう! –