Reference Language | Libraries | Comparison | Changes
ArduinoAPDS9960 : APDS class
readProximity()
Description
Retrieve the proximity read from the sensor. You can check if a proximity has been read by the sensor and may be retrieved using the APDS.proximityAvailable()
function.
Syntax
APDS.readProximity()
Parameters
None
Returns
The detected proximity that may range from 0 to 255 where 0 is the closest and 255 is the farthest.
The function returns -1 in case of error.
Example
/*
APDS9960 - Proximity Sensor
This example reads proximity data from the on-board APDS9960 sensor of the
Nano 33 BLE Sense and prints the proximity value to the Serial Monitor
every 100ms.
The circuit:
- Arduino Nano 33 BLE Sense
This example code is in the public domain.
*/
#include <Arduino_APDS9960.h>
void setup() {
Serial.begin(9600);
while (!Serial);
if (!APDS.begin()) {
Serial.println("Error initializing APDS9960 sensor!");
}
}
void loop() {
// check if a proximity reading is available
if (APDS.proximityAvailable()) {
// read the proximity
// - 0 => close
// - 255 => far
// - -1 => error
int proximity = APDS.readProximity();
// print value to the Serial Monitor
Serial.println(proximity);
}
// wait a bit before reading again
delay(100);
}
See Also
Reference Home
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a
Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.