import lejos.nxt.*; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author malmovich */ public class DriveTowardsLight extends Behavior { private Behavior[] m_behaviors; RCXLightSensor lightSensorA = new RCXLightSensor(SensorPort.S2); RCXLightSensor lightSensorB = new RCXLightSensor(SensorPort.S3); MotorPort[] motorsA = new MotorPort[] { MotorPort.B }; MotorPort[] motorsB = new MotorPort[] { MotorPort.C }; SensorActuatorConnection threadA; SensorActuatorConnection threadB; public DriveTowardsLight(Behavior[] bs, int lcdRow) { super("DTL",lcdRow); m_behaviors = bs; threadA = new SensorActuatorConnection(lightSensorA, motorsB); threadB = new SensorActuatorConnection(lightSensorB, motorsA); } public void run() { while(true) { setSup(true); threadA.run(); threadB.run(); setSup(false); delay(1000); } } private void setSup(boolean sup) { for(int i = 0; i < m_behaviors.length; i++) m_behaviors[i].setSuppress(sup); } }