filmov
tv
Create a stopwatch with Micro:bit and LCD display
Показать описание
A stopwatch is a timer device that can be used to measure the amount of time that has elapsed between the start and stop of the timer. Stopwatches can be mechanical, electronic, or software-based.
To create a stopwatch with Micro:bit and LCD I2C 16x2 display, you will need the following components:
- Micro:bit board
- LCD I2C 16x2 display
- Breadboard
- Jumper wires
Step 1: Set up the LCD display
Connect the I2C pins of the LCD display to the Micro:bit board. Use the following pin connections:
- SDA pin of the LCD display to pin 20 (SDA) of the Micro:bit board
- SCL pin of the LCD display to pin 19 (SCL) of the Micro:bit board
- VCC pin of the LCD display to the 5V pin of the Micro:bit board
- GND pin of the LCD display to the GND pin of the Micro:bit board
Step 2: Code the Micro:bit board
1- To code the Micro:bit board, you will need to use the MakeCode editor. Here are the steps to create a stopwatch:
2- Open the MakeCode editor and create a new project.
3- Drag the "show string" block from the Basic category to the workspace.
4- Replace the default text with "00:00:00".
5- Drag the "forever" block from the Basic category to the workspace.
6- Inside the "forever" block, add a "pause" block from the Basic category and set the duration to 1000 ms (1 second).
7- Add a variable called "milliseconds" and set its value to 0.
8- Inside the "forever" block, add a "change" block from the Variables category and set the variable to "milliseconds" and the value to 1.
9- Add a "if" block from the Logic category and set the condition to "milliseconds = 1000".
10-Inside the "if" block, add a "set" block from the Variables category and set the variable to "milliseconds" and the value to 0.
11- Inside the "if" block, add a "change" block from the Math category and set the variable to "seconds" and the value to 1.
12- Add variables called "seconds" and "minutes" and set their values to 0.
Inside the "if" block, add two "if" blocks from the Logic category and set the conditions to "seconds = 60" and "minutes = 60", respectively.
13- Inside each "if" block, set the variable to 0 and add a "change" block to increase the next variable by 1.
14- Inside each "if" block, update the "show string" block with the new time (e.g., "01:01:00").
Step 3: Upload the code to the Micro:bit board
Connect the Micro:bit board to your computer and click the "Download" button in the MakeCode editor. This will download the code onto the Micro:bit board.
Step 4: Test the stopwatch
To create a stopwatch with Micro:bit and LCD I2C 16x2 display, you will need the following components:
- Micro:bit board
- LCD I2C 16x2 display
- Breadboard
- Jumper wires
Step 1: Set up the LCD display
Connect the I2C pins of the LCD display to the Micro:bit board. Use the following pin connections:
- SDA pin of the LCD display to pin 20 (SDA) of the Micro:bit board
- SCL pin of the LCD display to pin 19 (SCL) of the Micro:bit board
- VCC pin of the LCD display to the 5V pin of the Micro:bit board
- GND pin of the LCD display to the GND pin of the Micro:bit board
Step 2: Code the Micro:bit board
1- To code the Micro:bit board, you will need to use the MakeCode editor. Here are the steps to create a stopwatch:
2- Open the MakeCode editor and create a new project.
3- Drag the "show string" block from the Basic category to the workspace.
4- Replace the default text with "00:00:00".
5- Drag the "forever" block from the Basic category to the workspace.
6- Inside the "forever" block, add a "pause" block from the Basic category and set the duration to 1000 ms (1 second).
7- Add a variable called "milliseconds" and set its value to 0.
8- Inside the "forever" block, add a "change" block from the Variables category and set the variable to "milliseconds" and the value to 1.
9- Add a "if" block from the Logic category and set the condition to "milliseconds = 1000".
10-Inside the "if" block, add a "set" block from the Variables category and set the variable to "milliseconds" and the value to 0.
11- Inside the "if" block, add a "change" block from the Math category and set the variable to "seconds" and the value to 1.
12- Add variables called "seconds" and "minutes" and set their values to 0.
Inside the "if" block, add two "if" blocks from the Logic category and set the conditions to "seconds = 60" and "minutes = 60", respectively.
13- Inside each "if" block, set the variable to 0 and add a "change" block to increase the next variable by 1.
14- Inside each "if" block, update the "show string" block with the new time (e.g., "01:01:00").
Step 3: Upload the code to the Micro:bit board
Connect the Micro:bit board to your computer and click the "Download" button in the MakeCode editor. This will download the code onto the Micro:bit board.
Step 4: Test the stopwatch