检索从传感器读取的颜色。您可以检查传感器是否已读取颜色,并且可以使用APDS.colorAvailable()
函数检索颜色。
用法
Int r, g, b;
APDS.readColor(r, g, b);
Int a;
APDS.readColor(r, g, b, a);
参数
此函数需要 3 或 4 个整数变量作为将存储读取颜色的参数:
r
:读取颜色的红色分量。g
:读取颜色的绿色分量。b
:读取颜色的蓝色分量。a
。环境光强度。
返回
None。
示例
/*
APDS-9960 - Color Sensor
This example reads color data from the on-board APDS-9960 sensor of the
Nano 33 BLE Sense and prints the color RGB (red, green, blue) values
to the Serial Monitor once a second.
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 color reading is available.
while (!APDS.colorAvailable()) {
delay(5);
}
int r, g, b;
// Read the color.
APDS.readColor(r, g, b);
// Print the values:
Serial.print("r = ");
Serial.println(r);
Serial.print("g = ");
Serial.println(g);
Serial.print("b = ");
Serial.println(b);
Serial.println();
// Wait a bit before reading again.
delay(1000);
}
相关用法
- Arduino Arduino_APDS9960 - readProximity()用法及代码示例
- Arduino Arduino_APDS9960 - readGesture()用法及代码示例
- 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 - readColor()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。