Skip to content

Latest commit

 

History

History
112 lines (67 loc) · 2.67 KB

playbulb-light.md

File metadata and controls

112 lines (67 loc) · 2.67 KB

Playbulb-light LED 智能灯

用本项目,支持Chrome浏览器使用Web蓝牙API操作Playbulb系列LED智能灯。

演示地址(含模拟器) @码上掘金

支持设备

目前经过测试的设备包括:

  1. 智能灯泡

  1. 触碰球

  1. 灯泡蜡烛

API

class Playbulb

创建 Playblue 智能设备

import {Playbulb} from 'jcode-bluetooth.js';
const device = new Playbulb();

async device.connect()

连接设备

await device.connect();
console.log(device.isConnected); // true

async device.disconnect()

断开连接

await device.disconnect();
console.log(device.isConnected); // false

device.isConnected

判断设备是否已连接

async device.setBrightness()

设置亮度,范围0-100

await device.connect();
await device.setBrightness(100);

async device.setColor(color)

设置灯泡颜色,支持CSS中任意合法的颜色值,如果是RGBA,则A值对应亮度0xff * (1 - alpha)

await device.connect();
await device.setColor('red'); // 将灯设置为红色

async device.setColorEffect(color, effect, speed)

设置灯泡的颜色效果,effect 效果包括:

  • 0x00 闪烁
  • 0x01 脉搏/呼吸灯
  • 0x02 彩色闪烁
  • 0x03 彩色渐变
  • 0x04 蜡烛效果

speed 为速度,范围0x00-0xff

async device.setFlashingColor(color, speed)

设置闪烁颜色,speed 为速度,范围0x00-0xff

async device.setPulsingColor(color, speed)

设置脉搏颜色,speed 为速度,范围0x00-0xff

async device.setRainbowJumpingColor(color, speed)

设置彩色闪烁颜色,speed 为速度,范围0x00-0xff

async device.setRainbowFadingColor(color, speed)

设置彩色渐变颜色,speed 为速度,范围0x00-0xff

async device.setCandlingColor(color, speed)

设置蜡烛效果颜色,speed 为速度,范围0x00-0xff

events

device 事件,可在 window 对象上捕获这些事件。

  • deviceconnected 设备连接成功。
  • devicedisconnected 设备断开连接。
  • devicestatechange 设备状态改变,包括亮度、颜色等。