Step 0. Using your web browser, go directly to https://makecode.microbit.org to land the MakeCode for micro:bit home page. You can bookmark this package to easily open this package for next project. In the My Projects section, click on the New Project
For more information about MakeCode, please go to our tutorial: What is MakeCode
Step 1. In the Toolbox, click on the Variables category and then click the Make a Variable button, and then In the New Variable name window, type “reading” as the variable name, then click on the Ok button
Step 2. Drag and drop a set number to 0 block inside the forever block, and choose reading from the drop-down menu.
Step 3. In the Toolbox, click on the Pins category under Advanced. Now, click and drag the analog read pin P0 block over and place it inside the placeholder of the set reading to 0 block. Then choose P0 from the drop-down menu if it has not already been selected
Step 4. Drag and drop a set reading to 0 block inside the forvever block just below the set reading to block , and choose new variable from the drop-down menu to create “number” as a new variable name.
Step 5. In the Toolbox, click on the Math category and Click and drag the square robot 0 block over and place it inside the placeholder of the set number to 0 block. Then choose integer ÷ from the drop-down menu
Step 6. Drag and drop a reading block from variable category over and place it inside the placeholder of the integer ÷ block , and change 0 to 50.
Step 7. In the Toolbox, click on the Basic category, click and drag the show number 0 block over and place it inside of the forever block. The simulator area will show 0
Step 8. Drag and drop a number block from variable category over and place it inside the placeholder of the show number 0 block
Step 9. In the Toolbox, click on the Logic category. Then click and drag the if-then-else block over and place it inside the forever block just below the show number block.
Step 10. Click on the Logic category again. Under the Comparison section, click and drag one of the blocks over, and place it on the placeholder of the if-then-else block (by default, the placeholder has a true-false block). Then choose “>” from the dropdown list.
Step 11. Drag and drop a number block from variable category over and place it on the frst placeholder of the Comparison block. Also, change the second placeholder of the Comparison block to 5
Step 12. Click on the Pins category and drag and drop the digital write pin P0 to 0 block over and place it inside the “then” section of the if-then-else block. Then choose P1 from the drop-down menu and change 0 to 1
Step 13. Right-click on the digital write pin P1 to 1 block and click Duplicate from the shortcut menu and you will get a duplicated block. change 0 to 1 and drag and drop the duplicated block inside the “else” section.
Step 14. Download this “.hex” file and send it to your MICROBIT disk.
Below is the full code we have done for you as reference:
Complete wiring and power up, You should see the brightness data on the LED matrix of micro:bit.
If the brightness value is greater than 5, the light will be lit, otherwise, the light will remain extinguished.
DownLoad Url osoyoo.com