diff --git a/docs/device/screen.md b/docs/device/screen.md index 5ca1b64d..fcf07258 100644 --- a/docs/device/screen.md +++ b/docs/device/screen.md @@ -91,3 +91,10 @@ basic.showString("d", 150) You will not see the LED at position `0,0` lit up because the `show string` function overwrites the whole display buffer. + +### Pins: P3, P4, P6, P7, P9, P10 + +These pins are coupled to the LED matrix display, and also it’s associated ambient light sensing mode. +To disable the display driver feature (which will automatically disable the light sensing feature) use the function [led.enable](/reference/led/enable). + +More information at http://tech.microbit.org/hardware/edgeconnector_ds/ . diff --git a/docs/reference/led.md b/docs/reference/led.md index 5d528df2..117aff0d 100644 --- a/docs/reference/led.md +++ b/docs/reference/led.md @@ -17,8 +17,9 @@ led.plotAll(); led.screenshot(); led.toggleAll(); led.setDisplayMode(DisplayMode.BackAndWhite); +led.enable(false) ``` ### See Also -[plot](/reference/led/plot), [unplot](/reference/led/unplot), [point](/reference/led/point), [brightness](/reference/led/brightness), [setBrightness](/reference/led/set-brightness), [stopAnimation](/reference/led/stop-animation), [plotBarGraph](/reference/led/plot-bar-graph), [fadeIn](/reference/led/fade-in), [fadeOut](/reference/led/fade-out), [plotAll](/reference/led/plot-all), [screenshot](/reference/led/screenshot), [toggle](/reference/led/toggle), [toggleAll](/reference/led/toggle-all), [setDisplayMode](/reference/led/set-display-mode) +[plot](/reference/led/plot), [unplot](/reference/led/unplot), [point](/reference/led/point), [brightness](/reference/led/brightness), [setBrightness](/reference/led/set-brightness), [stopAnimation](/reference/led/stop-animation), [plotBarGraph](/reference/led/plot-bar-graph), [fadeIn](/reference/led/fade-in), [fadeOut](/reference/led/fade-out), [plotAll](/reference/led/plot-all), [screenshot](/reference/led/screenshot), [toggle](/reference/led/toggle), [toggleAll](/reference/led/toggle-all), [setDisplayMode](/reference/led/set-display-mode), [enabled](/reference/led/enable) diff --git a/docs/reference/led/enable.md b/docs/reference/led/enable.md new file mode 100644 index 00000000..861be1b3 --- /dev/null +++ b/docs/reference/led/enable.md @@ -0,0 +1,33 @@ +# Enable + +Turns the LED screen on and off + +```sig +led.enable(false); +``` + +### Parameters + +* ``on`` is a [boolean](/reference/types/boolean) that defines the on/off state of the screen + +### Example: Turning off the screen + +This program turns off the screen when pressing button ``B`` + +```typescript +input.onButtonPressed(Button.B, () => { + led.enable(false) +}); +``` + +### Pins: P3, P4, P6, P7, P9, P10 + +These pins are coupled to the LED matrix display, and also it’s associated ambient light sensing mode. +To disable the display driver feature (which will automatically disable the light sensing feature) call the DAL function ``led.enable(false)``. +To turn the display driver back on again later, call ``led.enable(true)``. + +More information at http://tech.microbit.org/hardware/edgeconnector_ds/ . + +### See also + +[unplot](/reference/led/unplot), [point](/reference/led/point), [LED screen](/device/screen) diff --git a/libs/core/led.cpp b/libs/core/led.cpp index 029fc1bf..457dbf64 100644 --- a/libs/core/led.cpp +++ b/libs/core/led.cpp @@ -84,14 +84,24 @@ namespace led { /** * Sets the display mode between black and white and greyscale for rendering LEDs. - * @param mode TODO + * @param mode mode the display mode in which the screen operates */ //% weight=1 help=led/set-display-mode - //% parts="ledmatrix" + //% parts="ledmatrix" advanced=true void setDisplayMode(DisplayMode_ mode) { uBit.display.setDisplayMode((DisplayMode)mode); } + /** + * Turns on or off the display + */ + //% help=led/enable blockId=device_led_enable icon="\uf04d" + //% advanced=true parts="ledmatrix" + void enable(bool on) { + if (on) uBit.display.enable(); + else uBit.display.disable(); + } + /** * Takes a screenshot of the LED screen and returns an image. */ diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index 6c7be203..d2346ad3 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -488,12 +488,19 @@ declare namespace led { /** * Sets the display mode between black and white and greyscale for rendering LEDs. - * @param mode TODO + * @param mode mode the display mode in which the screen operates */ //% weight=1 help=led/set-display-mode - //% parts="ledmatrix" shim=led::setDisplayMode + //% parts="ledmatrix" advanced=true shim=led::setDisplayMode function setDisplayMode(mode: DisplayMode): void; + /** + * Turns on or off the display + */ + //% help=led/enable blockId=device_led_enable icon="\uf04d" + //% advanced=true parts="ledmatrix" shim=led::enable + function enable(on: boolean): void; + /** * Takes a screenshot of the LED screen and returns an image. */ diff --git a/sim/state/ledmatrix.ts b/sim/state/ledmatrix.ts index 403f5c8e..5692c852 100644 --- a/sim/state/ledmatrix.ts +++ b/sim/state/ledmatrix.ts @@ -9,6 +9,7 @@ namespace pxsim { brigthness = 255; displayMode = DisplayMode.bw; font: Image = createFont(); + disabled: boolean; animationQ: AnimationQueue; @@ -284,4 +285,8 @@ namespace pxsim.led { board().ledMatrixState.image.copyTo(0, 5, img, 0); return img; } + export function enable(on: boolean) { + board().ledMatrixState.disabled = !on; + runtime.queueDisplayUpdate(); + } } \ No newline at end of file diff --git a/sim/visuals/ledmatrix.ts b/sim/visuals/ledmatrix.ts index 7bba7f5d..70b11a3f 100644 --- a/sim/visuals/ledmatrix.ts +++ b/sim/visuals/ledmatrix.ts @@ -3,9 +3,9 @@ namespace pxsim.visuals { export function mkLedMatrixSvg(xy: Coord, rows: number, cols: number): - {el: SVGGElement, y: number, x: number, w: number, h: number, leds: SVGElement[], ledsOuter: SVGElement[], background: SVGElement} { - let result: {el: SVGGElement, y: number, x: number, w: number, h: number, leds: SVGElement[], ledsOuter: SVGElement[], background: SVGElement} - = {el: null, y: 0, x: 0, w: 0, h: 0, leds: [], ledsOuter: [], background: null}; + { el: SVGGElement, y: number, x: number, w: number, h: number, leds: SVGElement[], ledsOuter: SVGElement[], background: SVGElement } { + let result: { el: SVGGElement, y: number, x: number, w: number, h: number, leds: SVGElement[], ledsOuter: SVGElement[], background: SVGElement } + = { el: null, y: 0, x: 0, w: 0, h: 0, leds: [], ledsOuter: [], background: null }; result.el = svg.elt("g"); let width = cols * PIN_DIST; let height = rows * PIN_DIST; @@ -19,7 +19,7 @@ namespace pxsim.visuals { result.y = top; result.w = width; result.h = height; - result.background = svg.child(result.el, "rect", {class: "sim-display", x: left, y: top, width: width, height: height}) + result.background = svg.child(result.el, "rect", { class: "sim-display", x: left, y: top, width: width, height: height }) // ledsOuter result.leds = []; @@ -101,8 +101,16 @@ namespace pxsim.visuals { } public updateState() { - let bw = this.state.displayMode == pxsim.DisplayMode.bw - let img = this.state.image; + if (this.state.disabled) { + this.leds.forEach((led, i) => { + let sel = (led) + sel.style.opacity = 0 + ""; + }); + return; + } + + const bw = this.state.displayMode == pxsim.DisplayMode.bw + const img = this.state.image; this.leds.forEach((led, i) => { let sel = (led) let dx = i % this.DRAW_SIZE; diff --git a/sim/visuals/microbit.ts b/sim/visuals/microbit.ts index 95f4238e..d315fc12 100644 --- a/sim/visuals/microbit.ts +++ b/sim/visuals/microbit.ts @@ -334,12 +334,19 @@ namespace pxsim.visuals { svg.fill(this.buttons[index], btn.pressed ? theme.buttonDown : theme.buttonUp); }); - let bw = state.ledMatrixState.displayMode == pxsim.DisplayMode.bw - let img = state.ledMatrixState.image; - this.leds.forEach((led, i) => { - let sel = (led) - sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + ""; - }) + if (state.ledMatrixState.disabled) { + this.leds.forEach((led, i) => { + const sel = (led) + sel.style.opacity = "0"; + }) + } else { + const bw = state.ledMatrixState.displayMode == pxsim.DisplayMode.bw + const img = state.ledMatrixState.image; + this.leds.forEach((led, i) => { + const sel = (led) + sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + ""; + }) + } this.updatePins(); this.updateTilt(); this.updateHeading(); @@ -613,7 +620,7 @@ namespace pxsim.visuals { } // head - this.head = svg.child(this.g, "g", {class: "sim-head"}); + this.head = svg.child(this.g, "g", { class: "sim-head" }); svg.child(this.head, "circle", { cx: 258, cy: 75, r: 100, fill: "transparent" }) this.logos.push(svg.path(this.head, "sim-theme sim-theme-glow", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2")); this.logos.push(svg.path(this.head, "sim-theme sim-theme-glow", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7")); @@ -638,7 +645,7 @@ namespace pxsim.visuals { this.pins.push(svg.path(this.g, "sim-pin", "M359.9,317.3c-12.8,0-22.1,10.3-23.1,23.1V406H383v-65.6C383,327.7,372.7,317.3,359.9,317.3z M360,360.1c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C379.3,351.5,370.7,360.1,360,360.1z")); this.pins.push(svg.path(this.g, "sim-pin", "M458,317.6c-13,0-23.6,10.6-23.6,23.6c0,0,0,0.1,0,0.1h0V406H469c4.3,0,8.4-1,12.6-2.7v-60.7c0-0.4,0-0.9,0-1.3C481.6,328.1,471,317.6,458,317.6z M457.8,360.9c-10.7,0-19.3-8.6-19.3-19.3c0-10.7,8.6-19.3,19.3-19.3c10.7,0,19.3,8.7,19.3,19.3C477.1,352.2,468.4,360.9,457.8,360.9z")); - this.pins.forEach((p, i) => svg.hydrate(p, {title: pinTitles[i]})); + this.pins.forEach((p, i) => svg.hydrate(p, { title: pinTitles[i] })); this.pinGradients = this.pins.map((pin, i) => { let gid = "gradient-pin-" + i @@ -656,7 +663,7 @@ namespace pxsim.visuals { const btnw = 56.2; const btnn = 6; const btnnm = 10 - let btng = svg.child(this.g, "g", {class: "sim-button-group"}); + let btng = svg.child(this.g, "g", { class: "sim-button-group" }); this.buttonsOuter.push(btng); svg.child(btng, "rect", { class: "sim-button-outer", x: left, y: top, rx: btnr, ry: btnr, width: btnw, height: btnw }); svg.child(btng, "circle", { class: "sim-button-nut", cx: left + btnnm, cy: top + btnnm, r: btnn });