Block to negate number
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 641
- Avg merge
- 12h 4m
- Merged PRs (30d)
- 57
Description
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)
})
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked MakeCode demo and inspect how existing unary math blocks such as round, floor, square root, and sin are represented. Compare the requested negate operation with the current 0 - speed workaround. Done means a number variable can be negated directly in MakeCode and the resulting block works for the servo example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100