This time I want to share another project of Microbit and suitable for beginner.
Source of this project is from Raspberry pi.
Source of this project is from Raspberry pi.
The final result for this project will be :
If you press button A+B on microbit, it will set the timer to 0.
If you press button A, it will start counting your timer.
If you press button B, it will stop the timer.
No more further ado, let's code this Microbit.
Disclaimer Notice:
This is not a timer clock. It is only the timer just for fun.
Step 1 Setting up Timer
Drag on start and forever block to trash because you will not need it.
Put on button pressed event and select A+B
We want to add variable by clicking Variables and choose Make a Variables
Create Variable of time
Set time to 0 by dragging set block. It means when you press button A+B, you will get time to 0. Put show number block and drag your time variable into the block. This means you will display the time as well.
Now, you can test your code. Press button A+B, and the time will set to 0.
Step 2 Start and Stop Timer
We will start the timer by pressing button A and stop the timer by pressing button B. To do this, drag button pressed A.
We set a condition by using while block and drag Not block to the while block.
Drag button B pressed block after the not block.
Make 1 to your time variable every second (1 second = 1000 ms). Add a pause block to make your timer wait for 1 second.
Increase your time by 1.
Here is your final code:
No comments:
Post a Comment
Please kindly give nice comment that can improve our website in the future.
Thank you.
Regards,
DIY4 Pro