Purpose
To build a fan that is controlled by the temperature.
Materials
Background Knowledge
Bricks build-up
Software
Programming
Step 1
Click “Advanced” in the MakeCode drawer to see more choices.
In order to programme for the Ring:bit Bricks Pack, we need to add an extension. Click “Extensions” at the bottom of the drawer. Search “servo” in the dialogue box to download it.
Note: If you met a tip indicating codebase will be deleted due to incompatibility, you may continue as the tips tell or build a new project.
Step 2
Judge the returned value from the temperature sensor in “Forever” block, if the value is over 28 degrees, set the servos connected to P0 port turning; while less than 26 degrees, set the servos connected to P1 stopping turning.
Note: As the servo we used is in 360 degrees, the “servo” extension in MakeCode is suitable for servos in 180 degrees, therefore, setting the turning angle to 0 degree or 180 degrees will lead to the servo turning clockwisely or anti-clockwisely, and 90 degrees means to stop turning.
Code
Link: https://makecode.microbit.org/_UXj23eXHjXaC
You can also download it directly below:
Result
When the value is over 28 degrees, the fan turns; while less than 26 degrees, the fan stops turning.