我已经设法将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);
}