第一個任務:連結老師的電腦
程式碼:
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你好帥");
}
第二個任務:使用搖桿改變聲音
程式碼:
void setup() {// put your setup code here, to run once:
pinMode(8,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int x=analogRead(A0);
tone(8,x);
}
第三個任務:可移動的紅點
程式碼:
(Processing 上)import processing.serial.*;
Serial.serial;
void draw()
{
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=splittoken(now);
x=int(xy[0]);
y=int(xy[1]);
}
fill(255,0,0);
ellipse(x,y,100,100);
}
沒有留言:
張貼留言