RGB LED setting on WeDo hub
This commit is contained in:
parent
138d1a57d6
commit
96d4332f49
15
boosthub.js
15
boosthub.js
@ -48,15 +48,28 @@ class BoostHub extends Hub {
|
|||||||
setLEDColor (color) {
|
setLEDColor (color) {
|
||||||
const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL];
|
const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL];
|
||||||
if (characteristic) {
|
if (characteristic) {
|
||||||
|
let data = Buffer.from([0x05, 0x00, 0x01, 0x02, 0x02]);
|
||||||
|
characteristic.write(data);
|
||||||
if (color === false) {
|
if (color === false) {
|
||||||
color = 0;
|
color = 0;
|
||||||
}
|
}
|
||||||
const data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]);
|
data = Buffer.from([0x08, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, color]);
|
||||||
characteristic.write(data);
|
characteristic.write(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// setLEDRGB (red, green, blue) {
|
||||||
|
// const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL];
|
||||||
|
// if (characteristic) {
|
||||||
|
// let data = Buffer.from([0x05, 0x00, 0x01, 0x02, 0x03]);
|
||||||
|
// characteristic.write(data);
|
||||||
|
// data = Buffer.from([0x0a, 0x00, 0x81, 0x32, 0x11, 0x51, 0x00, red, green, blue]);
|
||||||
|
// characteristic.write(data);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
setMotorSpeed (port, speed, time) {
|
setMotorSpeed (port, speed, time) {
|
||||||
const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL];
|
const characteristic = this._characteristics[Consts.BLE.Characteristics.Boost.ALL];
|
||||||
if (characteristic) {
|
if (characteristic) {
|
||||||
|
24
wedo2hub.js
24
wedo2hub.js
@ -42,13 +42,29 @@ class WeDo2Hub extends Hub {
|
|||||||
|
|
||||||
|
|
||||||
setLEDColor (color) {
|
setLEDColor (color) {
|
||||||
const characteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.MOTOR_VALUE_WRITE];
|
const motorCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.MOTOR_VALUE_WRITE];
|
||||||
if (characteristic) {
|
const portCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.PORT_TYPE_WRITE];
|
||||||
|
if (motorCharacteristic && portCharacteristic) {
|
||||||
|
let data = Buffer.from([0x06, 0x17, 0x01, 0x01]);
|
||||||
|
portCharacteristic.write(data);
|
||||||
if (color === false) {
|
if (color === false) {
|
||||||
color = 0;
|
color = 0;
|
||||||
}
|
}
|
||||||
const data = Buffer.from([0x06, 0x04, 0x01, color]);
|
data = Buffer.from([0x06, 0x04, 0x01, color]);
|
||||||
characteristic.write(data);
|
motorCharacteristic.write(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setLEDRGB (red, green, blue) {
|
||||||
|
const motorCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.MOTOR_VALUE_WRITE];
|
||||||
|
const portCharacteristic = this._characteristics[Consts.BLE.Characteristics.WeDo2.PORT_TYPE_WRITE];
|
||||||
|
if (motorCharacteristic && portCharacteristic) {
|
||||||
|
let data1 = Buffer.from([0x01, 0x02, 0x06, 0x17, 0x01, 0x02]);
|
||||||
|
portCharacteristic.write(data1);
|
||||||
|
let data2 = Buffer.from([0x06, 0x04, 0x03, red, green, blue]);
|
||||||
|
console.log(data2);
|
||||||
|
motorCharacteristic.write(data2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user