pxt-calliope/docs/examples/stop-watch.md

21 lines
445 B
Markdown
Raw Normal View History

2017-05-24 17:47:19 +02:00
# Stop watch
2018-09-10 22:05:08 +02:00
Press ``A`` to start the counter. Press ``A`` again to stop and display the duration.
2017-05-24 17:47:19 +02:00
```blocks
let sec = 0
let start = 0
2018-09-10 22:05:08 +02:00
input.onButtonPressed(Button.A, function () {
2017-05-24 17:47:19 +02:00
if (!(start)) {
start = input.runningTime()
2018-09-10 22:05:08 +02:00
basic.showIcon(IconNames.Butterfly)
2017-05-24 17:47:19 +02:00
} else {
2018-09-10 22:05:08 +02:00
sec = input.runningTime() - start / 1000
2017-05-24 17:47:19 +02:00
start = 0
basic.clearScreen()
2018-09-10 22:05:08 +02:00
basic.showNumber(sec)
2017-05-24 17:47:19 +02:00
}
})
2018-09-10 22:05:08 +02:00
start = 0
```