All pastes #1246957 Raw Edit

DriveTowardsLight.java

public java v1 · immutable
#1246957 ·published 2008-11-06 15:49 UTC
rendered paste body
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);        }}