我已經設法將Arduino草圖連接到處理草圖,但我被困在如何讓Arduino控制處理中的對象。如何通過Arduino草圖控制處理中的對象?
使用傾斜傳感器時,目標是當傾斜傳感器傾斜一個方向時,它將以這種方式移動物體,然後當它傾斜時,另一種方式會以另一種方式移動物體。
任何人都可以幫忙嗎?
這是我的Arduino代碼:
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
Serial.println("Hello, World!");
delay(100);
}
這是我的代碼進行處理:
import processing.serial.*;
Serial myPort;
String val;
PShape bike;
void setup()
{
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
size(800, 600);
bike = createShape(RECT, 0, 0, 200, 200);
bike.setFill(color(102, 204, 0));
bike.setStroke(false);
}
void draw()
{
if (myPort.available() > 0)
{ // If data is available,
val = myPort.readStringUntil('\n'); // read it and store it in val
}
println(val); //print it out in the console
shape(bike, 0, 0);
}