Add 'timer' api docs (#339)

This commit is contained in:
Galen Nickel
2018-02-22 14:56:15 -08:00
committed by Peli de Halleux
parent d778232155
commit 6524b0a841
9 changed files with 190 additions and 8 deletions

View File

@ -11,36 +11,40 @@ namespace control {
}
/**
* Gets the elapsed time in millis since the last reset
* Get the elapsed time in millis since the last reset
*/
//% blockId=timerMillis block="%timer|millis"
//% help=control/timer/millis
millis(): number {
return control.millis() - this.start;
}
/**
* Gets the elapsed time in seconds since the last reset
* Get the elapsed time in seconds since the last reset
*/
//% blockId=timerSeconds block="%timer|seconds"
//% help=control/timer/seconds
seconds(): number {
return this.millis() / 1000;
}
/**
* Resets the timer
* Reset the timer
*/
//% blockId=timerRest block="%timer|reset"
//% help=control/timer/reset
reset() {
this.start = control.millis();
}
/**
* Pauses until the timer reaches the given amount of milliseconds
* Pause until the timer reaches the given amount of milliseconds
* @param ms how long to pause for, eg: 5, 100, 200, 500, 1000, 2000
*/
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
//% help=control/timer/pause-until
pauseUntil(ms: number) {
const remaining = this.millis() - ms;
const remaining = ms - this.millis();
pause(Math.max(0, remaining));
}
}