I am trying to read ultrasonic sensor reading from an Lego NXT robot using the programming language NBC (Next Byte Code). It says on the Lego Website that the sensor readings range from 0 -255 cm but when I output the sensor data, I get values above 255 sometimes; this usually happens when my Sensor reads in a value of 255; then after that it reads around 170 - 900 I don't know why it is doing this. Here is my code: (I am first reading in the sensor data then have the robot turn 45 degrees and repeat indefinitely just to examine how the data is being read.)
#include "NXTDefs.h"
// have the robot stay still and keep track of all the distances when turning around.
dseg segment
Distance udword 0
dseg ends
thread main
SetSensorUltrasonic(IN_4)
Forever:
ReadSensorUS(IN_4,Distance)
NumOut(0,10,Distance)
wait 1000
RotateMotor(OUT_B,100,180)
ClearSensor(IN_4)
ResetSensor(IN_4)
set Distance,0
jmp Forever
exit
endt