| Note: The program checks the touch sensor the moment it starts. So if you want the touch sensor to register as pushed in, you have to push it in before running the program. |
|
import josx.platform.rcx.*; /** * plays a buzzing sound if the robot starts with the touch * sensor pressed in. Otherwise it starts with a double beep **/ public class IfExample { public static void main (String[] args) throws Exception { // activate sensor Sensor.S1.setTypeAndMode (1, 0x20); Sensor.S1.activate(); // determin if sensor is pushed in or not if(Sensor.S1.readBooleanValue()) { Sound.buzz(); } else { Sound.twoBeeps(); } // wait for a second to complete the sound Thread.sleep(1000); } } |