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

Block to negate number #10327

Open
PSLLSP opened this issue Jan 1, 2025 · 0 comments
Open

Block to negate number #10327

PSLLSP opened this issue Jan 1, 2025 · 0 comments

Comments

@PSLLSP
Copy link

PSLLSP commented Jan 1, 2025

There is no block to negate number in Makecode. There is a block to negate logic value (not).

I miss a block to negate value of number. When number is constant, it is not problem, just negative number can be entered but when number is stored in variable, then entering negative value is "tricky". Block 0 - variable or -1 * variable can be used but this makes code just more complex. Could be a block -1 * number or negative number) added to Makecode? There is a block to have math operations on single parameter like round, floor, etc or square root, sin, etc, could be negate operation added to one of these blocks?

EXAMPLE

I want to control continuous servo with micro:bit. Servo can be controlled with value from -100 to 100, to define speed in percentage. I have custom function servo with one parameter, speed. It is speed in percentage and it is used to calculate duration of the control pulse. Note that when I want serve to run in opposite direction (with value -speed) I has to use 0 - speed block, not straight forward solution...

CODE

function servo (pspeed: number) {
    pins.servoSetPulse(AnalogPin.P0, 1500 + 5 * pspeed)
}
let speed = 100
basic.forever(function () {
    servo(speed)
    basic.pause(1000)
    servo(0 - speed)
    basic.pause(1000)
})

DEMO in Makecode

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