added led.enable (#294)
* added led.enable * fixed simulator support for led.enable
This commit is contained in:
parent
c6e38bd7a9
commit
76adc3c00a
@ -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/ .
|
||||
|
@ -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)
|
||||
|
33
docs/reference/led/enable.md
Normal file
33
docs/reference/led/enable.md
Normal file
@ -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)
|
@ -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.
|
||||
*/
|
||||
|
11
libs/core/shims.d.ts
vendored
11
libs/core/shims.d.ts
vendored
@ -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.
|
||||
*/
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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 = (<SVGStylable><any>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 = (<SVGStylable><any>led)
|
||||
let dx = i % this.DRAW_SIZE;
|
||||
|
@ -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;
|
||||
if (state.ledMatrixState.disabled) {
|
||||
this.leds.forEach((led, i) => {
|
||||
let sel = (<SVGStylable><any>led)
|
||||
const sel = (<SVGStylable><any>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 = (<SVGStylable><any>led)
|
||||
sel.style.opacity = ((bw ? img.data[i] > 0 ? 255 : 0 : img.data[i]) / 255.0) + "";
|
||||
})
|
||||
}
|
||||
this.updatePins();
|
||||
this.updateTilt();
|
||||
this.updateHeading();
|
||||
|
Loading…
Reference in New Issue
Block a user