/* * Created on Nov 9, 2004 by Ming Chow * * RCX code for telerobotics sample: starts and stops motor */ import josx.platform.rcx.*; import josx.rcxcomm.*; import java.io.*; public class MotorControl1RCX { // Constant for the power level of the motor // 7 is the maximum power level, and most powerful/fastest private static final int powerLevel=2; public static void main(String[] args) { rcxReceive(); } private static void rcxReceive() { RCXPort port; InputStream in; int cmd; try { // Opens communication to IR tower port=new RCXPort(); in=port.getInputStream(); while (true) { // The RCX listens to inputs (0/1 sent from PC) cmd=in.read(); setMotorAction(cmd); } } catch (IOException ioe) {}; } private static void setMotorAction(int actionFlag) { // If the signal sent from the PC is the number 1, then turn on the motor if (actionFlag==1) { Motor.C.setPower(powerLevel); Motor.C.forward(); } else // The signal sent from the PC is the number 0 Motor.C.stop(); } }