Methods
(async) read(measurementopt) → {Promise.<Number>}
Retrieve the distance that the proximity sensor is reading.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
measurement |
MeasurementUnit |
<optional> |
'i' |
The measurement to use, either 'i' for inches or 'c' for centimeters. |
Throws:
Example
// Read the measurement from the proximity sensor
const CENTIMETERS = 'c';
window.Agent.onReadyAsync()
.then(() => window.Agent)
.then(agent => agent.Peripherals.Proximity.read(CENTIMETERS))
.then(measurement => console.log(`The measurement is: ${measurement}`))
.catch(ex => {
switch (true) {
case ex instanceof AgentTimedOutException:
console.warn('The Agent timed out, have we connected the emulator?')
break;
case ex instanceof DisconnectedException:
console.warn('The peripheral is disconnected, can you plug it back in?');
break;
default:
console.error('An unknown error occured');
}
})