Welcome to the DFRobot blog
:
www.dfrobot.com/blog-tag-microbit.html
44
/
86
Goal: When the button is pressed, the servo rotates to 100
°
, and the LED penal of the micro: bit
shows “O”; When released, the servo stays at the 0
°
, and the LED penal of the micro: bit shows
“X”.
STEP 1
:
The “servo write” function under “Pins” is used to control the servo. Since the servo is
connected to P0, we will leave the “P0” as it is. The number “180” is the angle that we want the
servo to reach. By changing this value we can set the servo to rotate between 0
°
~180
°
.
STEP 2
:
Now, use the “if-else” function to determine the position of the servo based on the status of
the button. When the button is pressed, the servo goes to 100
°
, otherwise it stays at 0
°
. Also,
don’t forget to add the “O” and “X” to indicate the status of the button.