From dc7a4b78d1f47f4ead4b1b97fcad9d84ccf8bd3f Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 10 Sep 2018 13:05:08 -0700 Subject: [PATCH] updated stopwatch --- docs/examples/stop-watch.md | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/docs/examples/stop-watch.md b/docs/examples/stop-watch.md index ce304bd1..38fa74fe 100644 --- a/docs/examples/stop-watch.md +++ b/docs/examples/stop-watch.md @@ -1,30 +1,20 @@ # 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 -let msec = 0 let sec = 0 -let end = 0 -let d = 0 let start = 0 -input.onButtonPressed(Button.A, () => { +input.onButtonPressed(Button.A, function () { if (!(start)) { start = input.runningTime() - end = 0 + basic.showIcon(IconNames.Butterfly) } else { - d = input.runningTime() - start + sec = input.runningTime() - start / 1000 start = 0 basic.clearScreen() - basic.pause(1000) - sec = d / 1000 - msec = d % 1000 - basic.showString("" + sec + "." + msec) + basic.showNumber(sec) } }) -basic.forever(() => { - if (start) { - led.toggle(Math.randomRange(0, 5), Math.randomRange(0, 5)) - } -}) -``` \ No newline at end of file +start = 0 +```