2013-05-12 2 views
1

Arduino/Wiring을 사용하여 두 개의 조이스틱으로 두 개체를 움직이게하는 통신 방법을 제공하려고합니다. 당신이 볼 수 있듯이, 나는 각 문자 directiondirectionDPVector의이연결할 수없는 코드 arduino 통신 처리

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; 
} 

:

내가 통신에 사용하는 방법입니다. 내가 코드를 실행할 때, 그것은 나에게 오류를 제공합니다

Unreachable code in the line return directionD;

답변

4
return direction; 
return directionD; 

당신은 조건없이이 같은 두 개의 리턴 문을 가질 수 없습니다. 첫 번째 return 문이 실행될 때 두 번째 return 문에 도달 할 기회가 없습니다. 그것이 도달 할 수없는 성명서가있는 이유입니다.

+0

감사합니다. 감사합니다. – user2321978

0

@vishal_aim이 정확합니다.

두 가지 변수가 영향을받는 방법은 serialEvent에서 볼 수있는 PVector 클래스 또는 래퍼 (문자) 클래스의 두 인스턴스를 만든 다음 serialEvent에서받은 값을 두 인스턴스로 전달하는 것입니다.

또한 완전히 확신 할 수는 없지만 serialEvent가 첨부 된 값을 반환하도록 만들 수 있다고 생각하지 않습니다. void serialEvent는 Processing의 직렬 모듈에서 호출됩니다.