pxt-calliope/docs/examples/stop-watch.md
2018-09-10 13:05:08 -07:00

445 B

Stop watch

Press A to start the counter. Press A again to stop and display the duration.

let sec = 0
let start = 0
input.onButtonPressed(Button.A, function () {
    if (!(start)) {
        start = input.runningTime()
        basic.showIcon(IconNames.Butterfly)
    } else {
        sec = input.runningTime() - start / 1000
        start = 0
        basic.clearScreen()
        basic.showNumber(sec)
    }
})
start = 0