void distanceSensor_OnPolled(NxtPollable polledItem) { var distanceSensor = (NxtUltrasonicSensor) polledItem; var distance = distanceSensor.DistanceCm; if (distance < _thresholdDistanceCm) { if (!_blocked) { _blocked = true; Console.WriteLine("Obstacle Encountered {0}", distance); if (OnObstacleEncountered != null) { OnObstacleEncountered.Invoke(distanceSensor, new EventArgs()); } } } else { if (_blocked) { _blocked = false; Console.WriteLine("Obstacle Cleared {0}", distance); if (OnObstacleCleared != null) { OnObstacleCleared.Invoke(distanceSensor, new EventArgs()); } } } }
static void OnWithinThreshold(NxtPollable e) { Console.WriteLine("Obstacle in {0} cm", ((NxtUltrasonicSensor)e).DistanceCm); Reverse(); }
static void sonar_OnPolled(NxtPollable e) { //Console.WriteLine(((NxtUltrasonicSensor)e).DistanceCm); }
static void sound_OnPolled(NxtPollable e) { //Console.WriteLine(((NxtSoundSensor)e).Intensity); }