added stopwatch

This commit is contained in:
Peli de Halleux 2017-05-24 08:47:19 -07:00
parent 031faf9e81
commit 221d84d3bf
2 changed files with 35 additions and 0 deletions

View File

@ -50,6 +50,11 @@ Here are some fun programs for your @boardname@!
"description": "chart analog input on the LED screen",
"url":"/examples/plot-analog-pin",
"cardType": "example"
}, {
"name": "Stop Watch",
"description": "easy time tracking",
"url":"/examples/stop-watch",
"cardType": "example"
}]
```

View File

@ -0,0 +1,30 @@
# Stop watch
Press ``A`` to start the counter and
```blocks
let msec = 0
let sec = 0
let end = 0
let d = 0
let start = 0
input.onButtonPressed(Button.A, () => {
if (!(start)) {
start = input.runningTime()
end = 0
} else {
d = input.runningTime() - start
start = 0
basic.clearScreen()
basic.pause(1000)
sec = d / 1000
msec = d % 1000
basic.showString("" + sec + "." + msec)
}
})
basic.forever(() => {
if (start) {
led.toggle(Math.random(5), Math.random(5))
}
})
```