added stopwatch
This commit is contained in:
parent
031faf9e81
commit
221d84d3bf
@ -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"
|
||||
}]
|
||||
```
|
||||
|
||||
|
30
docs/examples/stop-watch.md
Normal file
30
docs/examples/stop-watch.md
Normal 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))
|
||||
}
|
||||
})
|
||||
```
|
Loading…
Reference in New Issue
Block a user