Skip to content

WeDo 2: Incorrect LED color setting #4984

Open
@alm-2000

Description

@alm-2000

Issue:
Unable to set some colors to WiDo2 HUB LED
Reason for behavior:
Incorrect code of function setLightHue (args) in src scratch-vm/src/extensions/scratch3_wedo2/index.js
WiDo2 LED color is not HUE or RGB color.

  1. If we use HUE with s: 1, v: 1 - then black (off) color impossible.
  2. If we use 3 byte RGB color - then we can't get orange or light green color. because Wedo 2 only distinguishes between 0 or 1 in each color byte. FF0001 is same with 020033, and 000201 is same with 00BFFB
    ToDo:
    Use 1-byte color scheme.
    Code correction:
//1)Change function setLightHue (args) to 
    setLightHue (args) {
        // Convert number to [0,10] interval 
        let inputColor = Cast.toNumber(args.HUE);
        inputColor = MathUtil.wrapClamp(inputColor , 0, 10);  
        this._peripheral.setLED_one_byteinputColor); 

        return new Promise(resolve => {
            window.setTimeout(() => {
                resolve();
            }, BLESendInterval);
        });
    }

// 2) After function setLED (inputRGB) create new

    setLED_one_byte (input) {
//There We need to put only 1 byte
//and get the cmd array of 4 elements instead of 6
        const weDoColor = [
            input        ];

        const cmd = this.generateOutputCommand(
            WeDo2ConnectID.LED,
            WeDo2Command.WRITE_RGB,
            weDoColor
        );

        return this.send(BLECharacteristic.OUTPUT_COMMAND, cmd);
    }

This solution is tested and works on my Scratch instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions