updated stopwatch

This commit is contained in:
Peli de Halleux 2018-09-10 13:05:08 -07:00
parent 72f1276038
commit dc7a4b78d1

View File

@ -1,30 +1,20 @@
# Stop watch # Stop watch
Press ``A`` to start the counter. Press ``A`` again to stop and display the count. Press ``A`` to start the counter. Press ``A`` again to stop and display the duration.
```blocks ```blocks
let msec = 0
let sec = 0 let sec = 0
let end = 0
let d = 0
let start = 0 let start = 0
input.onButtonPressed(Button.A, () => { input.onButtonPressed(Button.A, function () {
if (!(start)) { if (!(start)) {
start = input.runningTime() start = input.runningTime()
end = 0 basic.showIcon(IconNames.Butterfly)
} else { } else {
d = input.runningTime() - start sec = input.runningTime() - start / 1000
start = 0 start = 0
basic.clearScreen() basic.clearScreen()
basic.pause(1000) basic.showNumber(sec)
sec = d / 1000
msec = d % 1000
basic.showString("" + sec + "." + msec)
} }
}) })
basic.forever(() => { start = 0
if (start) { ```
led.toggle(Math.randomRange(0, 5), Math.randomRange(0, 5))
}
})
```