我正在尝试提供一种使用 Arduino/Wiring 的通信方法,以使两个对象用两个操纵杆移动。
这是我用于通信的方法:
public PVector serialEvent(Serial myPort) {
PVector direction = new PVector(0, 0);
PVector directionD = new PVector(0, 0);
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
if (myString != null) {
String [] dataJoystick1 = split(myString, ",");
// println (dataJoystick);
try {
direction.set(Float.parseFloat(dataJoystick1[0]), Float.parseFloat(dataJoystick1[1]), 0);
directionD.set(Float.parseFloat(dataJoystick1[2]), Float.parseFloat(dataJoystick1[3]), 0);
}
catch(NumberFormatException e) {
}
movimiento=direction;
movimientoD=directionD;
//==============================PJ1========
if (direction.x==0) {
movimiento.set(0, movimiento.y, 0);
}
if (direction.y==0) {
movimiento.set(movimiento.x, 0, 0);
}
}
//==============================PJ2========
if (directionD.x==0) {
movimiento.set(0, movimiento.y, 0);
}
if (directionD.y==0) {
movimiento.set(movimiento.x, 0, 0);
}
return direction;
return directionD;
}
如您所见,PVector
每个字符都有两个 sdirection
和directionD
. 但是,当我运行代码时,它给了我这个错误:
行返回方向D中无法到达的代码;