用Client連老師的Server
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(){
pinMode(2,INPUT);
}
void loop(){
analogRead(A0);X軸
analogRead(A1);Y軸
digitalRead(2);button
}
-----------------------------------------------------------------------------------------------
傳輸+analog 聲音(~1024)
void setup() {
pinMode(8, OUTPUT);
Serial.begin(38400);
}
void loop() {
int x = analogRead(A0); //X軸
int y = analogRead(A1);//Y軸
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.println();
tone(8, x );
}-----------------------------------------------------------------------------------------------
Arduino
void setup() {
Serial.begin(9600);
}
void loop() {
int x = analogRead(A0);
int y = analogRead(A1);
Serial.print(x);
Serial.print(" ");
Serial.print(y);
Serial.println();
delay(100);
}
Processing
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 = splitToken(now);
x = int(xy[0]);
y = int(xy[1]);
}
fill(255, 0, 0);
ellipse(x, y, 100, 100);
}
-----------------------------------------------------------------------------------------------
沒有留言:
張貼留言