I'm using ev3 ultrasonic sensor. And I'm writing a behavior based lejos code. I want to do some tasks when the ultrasonic sensor detects an object which is not further than 30 cm's. And this is my code:
public UltrasonicSensor(Port port)
{
sonar = new EV3UltrasonicSensor(port);
sonar.getDistanceMode().fetchSample(value, 0);
}
@Override
public boolean takeControl() {
// TODO Auto-generated method stub
return value[0] < 0.3;
public void action() {
....
}
@Override
public void suppress() {
// TODO Auto-generated method stub
suppressed = true;
}
But I think it is not the right way. How can I implement it in the right way?
Thanks for help,