This example shows how to read values from the distance sensor.
The following call selects the Move Hub in the simulator,
this is only necessary to run this demo without an actual connection to a device...
If you are using a Move Hub then this exemple expects the distance sensor to be
connected to port "C".
If you are using the Hub -which has only two ports- then you can change
the value POWERED_UP_PORT_C to POWERED_UP_PORT_A and connect the sensor to port "A"...
"Powered Up Distance sensor example" "lib/modules/standard.whl" "lib/modules/device.whl" "lib/modules/poweredUp.whl" "lib/modules/light.whl" "lib/modules/sensor.whl" "Hub" proc main() ; Select the device in the simulator... poweredUpSetDevice(LAYER_1, POWERED_UP_MOVE_HUB) ; Use port "C"... number inputPort = POWERED_UP_PORT_C sensorLayerSetMode(LAYER_1, inputPort, POWERED_UP_SENSOR_MODE_DISTANCE) number lastValue = -1 repeat ; Read the color value: number value = sensorLayerRead(LAYER_1, inputPort) ; Check if the value is changed: if value != lastValue ; The value is changed! lastValue = value ; Display the new distance value... clearConsole() printS("Distance:") printN(value) end end end