Case 62: The Gesture-controlled Fan
66. Case 62: The Gesture-controlled Fan#
66.2. Case Build-up#
Build it as the assembly steps suggest:
Build completion :
66.3. MakeCode Programming#
Click “Advanced” in the MakeCode drawer to see more choices.
For programming the ELECFREAKS Planetx Gesture Sensor, ELECFREAKS PlanetX Motor Fan, and the 8 RGB Rainbow LED Ring, enter “PlanetX” in the dialog box and click search to download it.
For programming the Nezha, click “Extensions” at the bottom of the drawer and search with “nezha” to download it.
Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.
Program as picture suggests#
Initialize the 8 RGB Rainbow LED Ring to connect to the J2 port of the Nezha expansion board.
Set when the gesture sensor detects upward gesture, judge whether the level is less than 8, if less than 8 then the variable level will automatically add one. Set when the gesture sensor detects a downward gesture, judge whether the level is greater than 0, if greater than 0 then the variable level is automatically minus one, and set the light to black. Set when the gesture sensor detects the gesture to the left, turn off the fan, and lights, and set the variable level to 0.
When the value of the variable level is not 0, set speed=level×10+20, set the speed of the motor fan module connected to the J1 port of which Zha expansion board to speed%, set the number of lights to be lit according to the value of level, and set the light color to blue.
Full procedure :
You may also download it directly:
Fan speed is controlled by gestures. Upward gestures control fan acceleration, downward gestures control fan deceleration, leftward gestures control fan stop rotation, and fan speed is displayed by the LED rings, and the faster the speed is, the stronger lights are lit.