Sonar Statement

Reads the value of the sonar sensor. The lower the value, the closes the sonar sensor is to the object. Note that there are two specific ports that must be used with the sonar sensor. Due to that, the sonar statement does not require a port parameter.

Syntax

  1. sonar();

Example

  1. //Move forward until the sonar sensor detects is close to the wall.
  2. void main()
  3. {
    1. motor(2,95);
    2. motor(4,95);
    3. while(sonar()>500)
      1. sleep(0.5);
    4. ao();
  4. }