从传感器检索接近度读数。您可以检查传感器是否已读取接近度,并且可以使用APDS.proximityAvailable()
函数检索。
用法
APDS.readProximity()
参数
None。
返回
检测到的接近度可能在 0 到 255 之间,其中 0 是最近的,255 是最远的。如果发生错误,该函数将返回 -1。
示例
/*
APDS-9960 - Proximity Sensor
This example reads proximity data from the on-board APDS-9960 sensor of the
Nano 33 BLE Sense and prints the proximity value to the Serial Monitor
every 100 ms.
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 APDS-9960 sensor.");
}
}
void loop() {
// Check if a proximity reading is available.
if (APDS.proximityAvailable()) {
// Read the proximity where:
// - 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);
}
相关用法
- Arduino Arduino_APDS9960 - readGesture()用法及代码示例
- Arduino Arduino_APDS9960 - readColor()用法及代码示例
- Arduino Arduino_APDS9960 - begin()用法及代码示例
- Arduino Arduino_APDS9960 - setGestureSensitivity()用法及代码示例
- Arduino Arduino_APDS9960 - colorAvailable()用法及代码示例
- Arduino Arduino_APDS9960 - gestureAvailable()用法及代码示例
- Arduino Arduino_APDS9960 - setInterruptPin()用法及代码示例
- Arduino Arduino_APDS9960 - end()用法及代码示例
- Arduino Arduino_APDS9960 - proximityAvailable()用法及代码示例
- Arduino Arduino_APDS9960 - setLEDBoost()用法及代码示例
- Arduino Arduino_APA102 - setBrightness()用法及代码示例
- Arduino Arduino_APA102 - begin()用法及代码示例
- Arduino Arduino_APA102 - Arduino_APA102(numLEDs, newDataPin , newClockPin)用法及代码示例
- Arduino Arduino_APA102 - setPixelColor()用法及代码示例
- Arduino Arduino_EMBRYO_2 - setLengthXY()用法及代码示例
- Arduino Arduino_LSM9DS1 - readGyroscope()用法及代码示例
- Arduino Arduino_LSM9DS1 - magneticFieldAvailable()用法及代码示例
- Arduino Arduino_MKRGPS - standby()用法及代码示例
- Arduino Arduino_EMBRYO_2 - end()用法及代码示例
- Arduino Arduino_LSM6DSOX - gyroscopeAvailable()用法及代码示例
- Arduino Arduino_EMBRYO_2 - terminateInterrupt()用法及代码示例
- Arduino Arduino_OplaUI - setSuffix()用法及代码示例
- Arduino Arduino_MKRGPS - longitude()用法及代码示例
- Arduino Arduino_MKRGPS - latitude()用法及代码示例
- Arduino Arduino_MKRGPS - satellites()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Arduino_APDS9960 - readProximity()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。