10. Case 08: Search for Light

10.1. Purpose


  • Build a Wonder Rugged Kit that can search for light.

10.2. Materials


  • micro:bit Wonder Rugged Kit

10.3. Background Knowledge


10.4. Software


MicroSoft makecode

10.5. Program


Step 1

Click “Advanced” in the drawer of MakeCode to see more choices.

../../_images/Mecanum_wheel_car_kit_case_01_01.png

For programming the Wonder Rugged Kit, we need to add a package. Click “Extensions” at the bottom of the drawer and then search “Wukong” in the dialogue box to download it.

../../_images/Mecanum_wheel_car_kit_case_01_02.png

Note:If you get a warning indicating some packages will be removed because of incompatibility issues, you can follow the prompts or create a new project in the menu.

Step 2

Click Wukong to choose mecanum block.

../../_images/Mecanum_wheel_car_kit_case_01_03.png

Step 3

Drag mecanum into on start block and set the connection for servos accordingly, then initialize the LEDs.

../../_images/Mecanum_wheel_car_kit_case_08_05.png

Step 4

Set variable i as the brightness level and judge the value of it. If the value of i is below 50, the car turns left; or it moves forward.

../../_images/Mecanum_wheel_car_kit_case_08_06.png

Program

Links: https://makecode.microbit.org/_Kv3dfY02f52g

You can also download it directly:

Result

The car spins itself if no light being detected, or it goes straight towards the light.

10.6. Exploration

If we want the farther away the car is from the light source, the faster it is; and the closer it is to the light source, the slower it is, how to programme?

10.7. FAQ


10.8. Relevant Files