色彩传感器#
初始化颜色传感器类#
The colorsensor constructor creates a colorsensor object in the specified Smart Port:
范围 |
描述 |
|---|---|
|
颜色传感器连接到的有效 智能端口。 |
// Construct a Color Sensor "ColorSensor" with the
// colorsensor class.
colorsensor ColorSensor = colorsensor(PORT1)
This ColorSensor object will be used in all subsequent examples throughout this API documentation when referring to colorsensor class methods.
类方法#
colorname3()#
The colorname3() command returns the closest color detected to red, green, or blue.
Returns: A colorType that represents the name of the closest color detected to red, green, or blue.
// Get the name of the detected color.
colorType c = ColorSensor.colorname3();
colorname()#
The colorname() command returns the name of the closest color detected to the preset colorType values.
Returns: A colorType that represents the name of the closest color detected to twelve possible values.
// Get the name of the detected color.
colorType c = ColorSensor.colorname();
hue()#
The hue() method returns the hue value detected by the Color Sensor.
**返回:**表示色调的整数。
brightness()#
The brightness(bRaw) method reads the brightness value from the Color Sensor.
参数 |
描述 |
|---|---|
|
Whether to return the raw value detected by the Color Sensor. The default is |
**返回:**表示亮度的整数。
isNearObject()#
The isNearObject() method returns if the proximity sensor detects an object.
Returns: true if near an object. false if it is not.
// Check if the Color Sensor is near an object.
if ColorSensor.isNearObject(){
print("near object");
}
setLight()#
该方法通过以下方式调用:
The setLight(value) method sets the Color Sensor LED on or off.
参数 |
描述 |
|---|---|
|
A valid |
**返回:**无。
The setLight(intensity, units) method sets the Color Sensor LED on or off.
参数 |
描述 |
|---|---|
|
设置灯光强度的值。 |
|
The only valid unit for intensity is |
**返回:**无。
detects()#
The detects(color) command checks if the color sensor is detecting a colorType color.
参数 |
描述 |
|---|---|
|
A |
**返回:**一个布尔值,指示是否已检测到颜色。
objectDetected()#
The objectDetected(callback) method registers a function to be called when an object detected event occurs.
参数 |
描述 |
|---|---|
|
当发生对象检测事件时将调用的函数。 |
**返回:**无。
// Define the detected function with a void return type,
// showing it doesn't return a value.
void detected() {
// The Brain will print that the Color Sensor detected
// an object to the Brain's screen.
Brain.Screen.print("object detected");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run detected when the Color Sensor detects an object.
ColorSensor.objectDetected(detected);
}
timestamp()#
The timestamp() method requests the timestamp of the last received status packet from the Color Sensor.
**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。
installed()#
The installed() command returns if the color sensor is installed.
**返回:**一个布尔值,指示颜色传感器是否已安装。