1. korak: Napravi
Što je to?
Make a simple timer using the new micro:bit's touch logo sensor.
Vodič za kodiranje
Što ćeš naučiti
- How to use the new micro:bit's touch logo sensor to trigger different events when you touch it and when you let go
- How to use variables, mathematical operators and a system clock to measure time
- How to convert units (milliseconds to seconds) using mathematical operators
Kako to radi
- The program times how long in you hold your finger down on the gold logo on the new micro:bit
- The micro:bit measures how long it's been switched on in milliseconds (thousands of a second). This is called the running time.
- The 'on logo touched' block senses when you first touch the logo. It shows a heart on the LED display and sets a variable called start to capture the current running time.
- The 'on logo released' block senses when you let go of the logo. The code then subtracts the start time from the new running time. The difference between the running time when you let go and the time when you touched it is the total time you held your finger on the logo. This is stored in a variable called time.
- The code then converts the time from milliseconds to seconds by dividing it by 1000 and shows it on the LED display.
- 'On logo touched' only triggers when you first put your finger on the logo, unlike the 'on logo pressed' block used in the Touch emotion badge project, which behaves like the A and B button and only triggers when you press and let go of the button.
Što ti treba
- new micro:bit with sound (or MakeCode simulator)
- Uređivač za MakeCode
- baterije (prema potrebi)
2. korak: Kodiraj
3. korak: Unaprijedi
- Modify the program so a different icon or your own picture appears when you touch the logo.
- Add a variable to track the maximum time recorded.
- Učini mjerač vremena preciznijim tako da upotrijebiš razlomke umjesto cijelih brojeva (integera).