package RCX2; import josx.platform.rcx.*; /** *Manages RCX sensors for CapnKirk class. */ public class Sensors { public static int SVwhite; public static int SVblack; final public static int SVlightTolerance = 10; /** *Initializes all sensors. Sets types and modes for each sensor, activates *them, defines forward and black and white for the light sensor. */ public static void init(){ Sensor.S1.setTypeAndMode(SensorConstants.SENSOR_TYPE_LIGHT, SensorConstants.SENSOR_MODE_PCT); Sensor.S3.setTypeAndMode(SensorConstants.SENSOR_TYPE_TOUCH, SensorConstants.SENSOR_MODE_BOOL); Sensor.S1.activate(); Sensor.S3.activate(); defineWhite(); defineBlack(); LightListener lighter = new LightListener(); Sensor.S1.addSensorListener(lighter); BumperListener bumper = new BumperListener(); Sensor.S3.addSensorListener(bumper); }//init //============================================ //Forward, White and Black defining methods. //============================================ /** *Defines what white is for the light sensor. Waits for user to press the *View button then sets and echoes the value. */ private static void defineWhite(){ try{ TextLCD.print("white"); Button.VIEW.waitForPressAndRelease(); SVwhite = Sensor.S1.readValue(); Sound.beep(); LCD.showNumber(SVwhite); Thread.sleep(750); LCD.clear(); }catch (InterruptedException ie){ Sound.buzz(); TextLCD.print("Fail"); } }//defineWhite /** *Defines what black is for the light sensor. Waits for user to press the *View button, then sets and echoes the value. */ private static void defineBlack(){ try{ TextLCD.print("black"); Button.VIEW.waitForPressAndRelease(); SVblack = Sensor.S1.readValue(); Sound.beep(); LCD.showNumber(SVblack); Thread.sleep(750); LCD.clear(); }catch (InterruptedException ie){ Sound.buzz(); TextLCD.print("Fail"); } }//defineBlack }//Sensors