1.網路連線

//Client 可以是任何人
import processing.net.*;//宣告
Client client;
void setup() {//初始化
size(100, 100);///老師的serverIP:120.125.70.53
client = new Client(this, "120.125.70.53", 6666);
}
void draw() {
}
void mousePressed() {
client.write("Hello");
}
2.連接麵包板用遙感控制聲音
void setup() {
// put your setup code here, to run once:
//pinMode(2,INPUT);
pinMode(8,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int x=analogRead(A0);//Y軸
tone(8,x);
}
3.用遙桿控制,顯示x、y座標位置

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int x=analogRead(A0);//x軸
int y=analogRead(A1);//y軸
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.println();
delay(100);
}
3.在畫面上顯示遙桿移動的畫面


import processing.serial.*; Serial serial; void setup() { size(1024,1024); serial=new Serial(this,"COM4",9600); } int x=512,y=512; void draw() { background(255); if(serial.available()>0){ String now=serial.readString(); String[] xy=splitTokens(now); x=int (xy[0]); y=int (xy[1]); } fill(255,0,0); ellipse(x,y,100,100); }
沒有留言:
張貼留言