![]() The index number should usually be zero except in special cases as indicated in the sensor appendix. If you want to obtain a single value that is not a percentage then use Sensor.ReadRawValue(port number, index). For example, the ultrasound sensor in mode 0 returns an integer value in the range 0-2550(?) which represents the distance to the reflecting object in mm, and the color sensor in mode 2, 'detect colors', returns a color code from 0-7 (0=unknown, 1=black etc). Sometimes you will want to obtain from a sensor a single value that is not a percentage.This will return 0 if the touch sensor's button is not pressed and 100 if it is pressed. For example, to obtain a reading from a touch sensor on port 1, use Sensor.ReadPercent(1). To obtain such a percentage value from the sensor, use Sensor.ReadPercent(port number). ![]() Some modes of some sensors return a percentage value (a value between 0 and 100).It is important to always set the mode of the sensor before it is used. For example, to set a color sensor on port 3 to mode 1 (ambient light intensity) use Sensor.SetMode(3, 1). To set the desired mode for the sensor you are using, use Sensor.Setmode(port number, mode). Some information on the different modes can be found below, and more can be found in the sensor appendix. ![]() ![]() As in the standard Lego EV3 software, many sensors can be used in different modes.
0 Comments
Leave a Reply. |