2016-03-26 00:47:20 +01:00
|
|
|
# Magnetic Force
|
|
|
|
|
2016-06-09 21:34:56 +02:00
|
|
|
Find the amount of magnetic force (the strength of a magnet) in the direction you say.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
input.magneticForce(Dimension.X);
|
|
|
|
```
|
|
|
|
|
2016-06-09 21:34:56 +02:00
|
|
|
## ~hint
|
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
The @boardname@ measures magnetic force with **microteslas**.
|
2016-06-09 21:34:56 +02:00
|
|
|
|
|
|
|
## ~
|
|
|
|
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Parameters
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
* ``dimension`` means which direction the @boardname@ should measure
|
2016-07-15 23:53:52 +02:00
|
|
|
magnetic force in: either `Dimension.X` (the left-right direction),
|
|
|
|
`Dimension.Y` (the forward/backward direction), or `Dimension.Z`
|
|
|
|
(the up/down direction)
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Returns
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
* a [number](/types/number) of microteslas that means the strength of the magnet
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## Example: metal detector
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
This program makes the center LED of the @boardname@ get brighter when
|
2016-06-09 21:34:56 +02:00
|
|
|
the magnetic force is stronger, and dimmer when it is weaker.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
led.plot(2, 2)
|
|
|
|
basic.forever(() => {
|
2016-06-14 23:01:00 +02:00
|
|
|
let f = input.magneticForce(Dimension.X)
|
2016-03-26 00:47:20 +01:00
|
|
|
led.setBrightness(f / 2000)
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
## See also
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-04-18 18:47:34 +02:00
|
|
|
[compass heading](/reference/input/compass-heading)
|