|
我想從 arduino 傳送數據到 processing我是使用分別 兩邊都寫程式 來傳送
可是目前只知道 如何傳送一個數據
想知道如何傳送分別三個 請問程式要如何改
arduino
int Red = 0;
int Green = 1;
int Blue = 2;
void setup(){
Serial.begin(9600);
}
void loop(){
int val1 = analogRead(Red);
int val2 = analogRead(Green);
int val3 = analogRead(Blue);
Serial.write(val1);
Serial.write(val2);
Serial.write(val3);
delay(150);
}
processing
import processing.serial.*;
Serial serial;
int Red;
int Green;
int Blue;
void setup(){
size(305,200);
serial = new Serial(this, "COM17", 9600);
}
void draw(){
if(serial.available() >0){
Red = serial.read();
Green = serial.read();
Blue = serial.read();
println(Red);
background(255);
fill(255,0,0);
rect(Green, 80, 50, 50);
//fill(0 ,0 ,0);
//rect(Green , 90 ,50 ,50);
}
} |
|