Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeDo 2: Incorrect LED color setting #4984

Open
alm-2000 opened this issue Oct 22, 2024 · 0 comments
Open

WeDo 2: Incorrect LED color setting #4984

alm-2000 opened this issue Oct 22, 2024 · 0 comments

Comments

@alm-2000
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant