|
楼主 |
发表于 2021-9-20 16:15
|
显示全部楼层
这是processing的完整代码
import processing.serial.*;
Serial port;
void setup(){
port=new Serial(this,"COM7",9600); //Arduino板的端口号
size(800,200);
}
void draw(){
fill(255,0,0);
rect(50,50,100,100);
fill(0,255,0);
rect(250,50,100,100);
fill(0,0,255);
rect(450,50,100,100);
fill(0,0,0);
rect(650,50,100,100);
if((mouseX>=50)&(mouseX<=150)&(mouseY>=50)&(mouseY<=150))
{
println("a");
port.write("a");
}
else if((mouseX>=250)&(mouseX<=350)&(mouseY>=50)&(mouseY<=150))
{
println("b");
port.write("b");
}
else if((mouseX>=450)&(mouseX<=550)&(mouseY>=50)&(mouseY<=150))
{
println("c");
port.write("c");
}else if((mouseX>=650)&(mouseX<=750)&(mouseY>=50)&(mouseY<=150))
{
println("d");
port.write("d");
}else{
println("e");
port.write("e");
}
} |
|