diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 2cc2e235..980cc2f9 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -52,6 +52,9 @@ "console.logValue|param|value": "to write", "console.sendToScreen": "Sends the log messages to the brick screen and uses the brick up and down buttons to scroll.", "control": "Program controls and events.", + "control.Timer.millis": "Gets the elapsed time in millis", + "control.Timer.reset": "Resets the timer", + "control.Timer.seconds": "Gets the elapsed time in seconds", "control.allocateNotifyEvent": "Allocates the next user notification event", "control.deviceFirmwareVersion": "Determine the version of system software currently running.", "control.dmesg": "Write data to DMESG debugging buffer.", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 34b89842..9bedc605 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -47,7 +47,18 @@ "console.log|block": "console|log %text", "console.sendToScreen|block": "send console to screen", "console|block": "console", + "control.Timer.millis|block": "%timer|millis", + "control.Timer.reset|block": "%timer|reset", + "control.Timer.seconds|block": "%timer|seconds", "control.raiseEvent|block": "raise event|from %src|with value %value", + "control.timer1|block": "timer 1", + "control.timer2|block": "timer 2", + "control.timer3|block": "timer 3", + "control.timer4|block": "timer 4", + "control.timer5|block": "timer 5", + "control.timer6|block": "timer 6", + "control.timer7|block": "timer 7", + "control.timer8|block": "timer 8", "control|block": "control", "motors.Motor.angle|block": "%motor|angle", "motors.Motor.clearCounts|block": "%motor|clear counts", diff --git a/libs/core/console.ts b/libs/core/console.ts index dc911e8b..cb220ae3 100644 --- a/libs/core/console.ts +++ b/libs/core/console.ts @@ -58,7 +58,7 @@ namespace console { namespace console.screen { const maxLines = 100; - const screenLines = 8; + const screenLines = 10; let lines: string[]; let scrollPosition = 0; @@ -66,8 +66,8 @@ namespace console.screen { if (!lines) { lines = []; console.addListener(log); - brick.buttonUp.onEvent(ButtonEvent.Click, () => scroll(-1)) - brick.buttonDown.onEvent(ButtonEvent.Click, () => scroll(1)) + brick.buttonUp.onEvent(ButtonEvent.Click, () => scroll(-3)) + brick.buttonDown.onEvent(ButtonEvent.Click, () => scroll(3)) } } diff --git a/libs/core/pxt.json b/libs/core/pxt.json index d4260e94..adfb69d5 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -11,6 +11,7 @@ "mmap.cpp", "control.cpp", "console.ts", + "timer.ts", "serialnumber.cpp", "buttons.ts", "png.cpp", diff --git a/libs/core/timer.ts b/libs/core/timer.ts new file mode 100644 index 00000000..c3106be9 --- /dev/null +++ b/libs/core/timer.ts @@ -0,0 +1,51 @@ +namespace control { + //% fixedInstances + export class Timer { + start: number; + + constructor() { + this.start = control.millis(); + } + + /** + * Gets the elapsed time in millis + */ + //% blockId=timerMillis block="%timer|millis" + millis(): number { + return control.millis() - this.start; + } + + /** + * Gets the elapsed time in seconds + */ + //% blockId=timerSeconds block="%timer|seconds" + seconds(): number { + return this.millis() / 1000; + } + + /** + * Resets the timer + */ + //% blockId=timerRest block="%timer|reset" + reset() { + this.start = control.millis(); + } + } + + //% whenUsed fixedInstance block="timer 1" + export const timer1 = new Timer(); + //% whenUsed fixedInstance block="timer 2" + export const timer2 = new Timer(); + //% whenUsed fixedInstance block="timer 3" + export const timer3 = new Timer(); + //% whenUsed fixedInstance block="timer 4" + export const timer4 = new Timer(); + //% whenUsed fixedInstance block="timer 5" + export const timer5 = new Timer(); + //% whenUsed fixedInstance block="timer 6" + export const timer6 = new Timer(); + //% whenUsed fixedInstance block="timer 7" + export const timer7 = new Timer(); + //% whenUsed fixedInstance block="timer 8" + export const timer8 = new Timer(); +} \ No newline at end of file