Rewrote in simple language. API might not be functional.
This commit is contained in:
parent
e604b27c4f
commit
cd56181703
@ -1,27 +1,35 @@
|
||||
# Magnetic Force
|
||||
|
||||
Get the magnetic force (micro Teslas), in one of three specified dimensions.
|
||||
Find the amount of magnetic force (the strength of a magnet) in the direction you say.
|
||||
|
||||
```sig
|
||||
input.magneticForce(Dimension.X);
|
||||
```
|
||||
|
||||
## ~hint
|
||||
|
||||
The micro:bit measures magnetic force with **microteslas**.
|
||||
|
||||
## ~
|
||||
|
||||
|
||||
### Parameters
|
||||
|
||||
* dimension : [String](/reference/types/string) - one of three values specifying the axis of the force: ``x`` (left/right); ``y`` (forward/backwards); ``z`` (up/down); ``strength`` (the length of the vector)
|
||||
* a [string](/reference/types/string) that says which direction the micro:bit should measure magnetic force in: either `x` (the left-right direction), `y` (the forward/backward direction), or `z` (the up/down direction)
|
||||
|
||||
### Returns
|
||||
|
||||
* [Number](/reference/types/number) - magnetic force, in micro-Teslas.
|
||||
* a [number](/reference/types/number) of microteslas that means the strength of the magnet
|
||||
|
||||
### Example: metal detector
|
||||
|
||||
The following example uses the `magnetic force` to control the brightness of the screen. When the magnetic force increases, the center LED will appear brighter.
|
||||
This program makes the center LED of the micro:bit get brighter when
|
||||
the magnetic force is stronger, and dimmer when it is weaker.
|
||||
|
||||
```blocks
|
||||
led.plot(2, 2)
|
||||
basic.forever(() => {
|
||||
let f = input.magneticForce(Dimension.X)
|
||||
let f = input.magneticForce("x")
|
||||
led.setBrightness(f / 2000)
|
||||
})
|
||||
```
|
||||
@ -29,4 +37,3 @@ basic.forever(() => {
|
||||
### See also
|
||||
|
||||
[compass heading](/reference/input/compass-heading)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user