Skip to content

LED灯控制

实验箱提供RGB三色led灯控制,包括一个红色led灯,一个绿色led灯,一个蓝色led灯。

该模块提供实验箱Led灯控制功能:

导入模块

typescript
import led from '@ohos.openvalley.led';

turnOn

turnOn(): boolean

亮起指定的led灯。

系统能力: SystemCapability.Sensors.EducationDeviceService

参数:

参数名类型必填说明
ledTypeLedType指定Led灯

返回值:

类型说明
boolean执行成功/失败

示例:

typescript
// 亮起红色led灯
var result = led.turnOn(LedType.RED);

turnOff

turnOff(): boolean

熄灭指定的led灯。

系统能力: SystemCapability.Sensors.EducationDeviceService

参数:

参数名类型必填说明
ledTypeLedType指定Led灯

返回值:

类型说明
boolean执行成功/失败

示例:

typescript
// 熄灭红色led灯
var result = led.turnOff(LedType.RED);

LedType

枚举,led灯类型。

名称默认值描述
RED0红色led灯
GREEN1绿色led灯
BLUE2蓝色led灯