1. ultrasonic sensor[index] distance to an object (cm)

Ultrasonic Sensor - 图1

Reports the distance of the obstacle detected by the ultrasonic sensor

How to Use

Ultrasonic sensors can be used to detect distance.
Value range: 4–300 cm
The number in this block indicates the place of an ultrasonic sensor among the ones connected to Halocode. As shown in the following figure, the number 1 indicates the first ultrasonic sensor connected to Halocode, 2 indicates the second one, and so on.
Ultrasonic Sensor - 图2
The value is 300 cm by default if the distance of the obstacle is shorter than 4 cm or longer than 300 cm.
You can select the check box on the left of this block to see the distance detected by the ultrasonic sensor on the stage.
Note: This is a reporter block that must be used in combination with another block requiring data.

Example

Ultrasonic Sensor - 图3

When you press the space key, the LED matrix displays the distance of the obstacle sensed by the ultrasonic sensor.
Note: Ensure that you have connected an LED matrix to Halocode.


2. ultrasonic sensor[index] outside the distance range?

Ultrasonic Sensor - 图4

Detemines whether the obstacle detected by the specified ultrasonic sensor is out of the distance range

How to Use

The distance range refers to the range of the distance that can be detected by the ultrasonic sensor, that is, 5 to 300 cm.
Note: This is a Boolean block that contains a condition. Use it in combination with another block that requires a condition.

Example

Ultrasonic Sensor - 图5

After you press the space key, the LED matrix is turned off if the obstacle detected by the ultrasonic sensor is out of the distance range; and it displays the distance between the obstacle and ultrasonic sensor if the obstacle is within the distance range.
Note: Ensure that you have connected an LED matrix to Halocode.