pxt-calliope/docs/reference/input/magnetic-force.md

33 lines
832 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# Magnetic Force
Get the magnetic force (micro Teslas), in one of three specified dimensions.
```sig
input.magneticForce(Dimension.X);
```
### Parameters
2016-04-13 17:27:45 +02:00
* 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)
2016-03-26 00:47:20 +01:00
### Returns
2016-04-13 17:27:45 +02:00
* [Number](/reference/types/number) - magnetic force, in micro-Teslas.
2016-03-26 00:47:20 +01:00
### 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.
```blocks
led.plot(2, 2)
basic.forever(() => {
let f = input.magneticForce(Dimension.X)
led.setBrightness(f / 2000)
})
```
### See also
2016-04-13 17:27:45 +02:00
[compass heading](/input/compass-heading)
2016-03-26 00:47:20 +01:00