Elecrow on-line store, make your making easier.
https://www.elecrow.com/
Material:
Micro:bit
x1
Crowtail- Base Shield for Micro:bit
x1
Crowtail- 9G Servo
x1
Lesson11.Magnetic Field Detection
This lesson will teach you detect the magnetic filed , we use a magnet simulate the magnetic field,
when the magnetic sensor close to the magnet, it will have response and the LED will light on.
Connect the Crowtail- Magenet switch to P0 interface and connect the crowtail - LED to P1
interface.
let
angle =
0
input
.
onButtonPressed
(Button.A, () => {
angle +=
0
-
Math
.
max
(
0
,
5
)
pins
.
servoWritePin
(AnalogPin.P0, angle)
led
.
stopAnimation
()
})
input
.
onButtonPressed
(Button.B, () => {
angle +=
Math
.
min
(
180
,
5
)
pins
.
servoWritePin
(AnalogPin.P0, angle)
led
.
stopAnimation
()
})
angle =
90
pins
.
servoWritePin
(AnalogPin.P0, angle)
basic
.
forever
(() => {
basic
.
showNumber
(angle)
})