support for led.plotBrightness (#494)
* support for led.plotBrightness * fixing c++ build * fixed blockid
This commit is contained in:
parent
e1764567c5
commit
e7c1915076
@ -22,4 +22,5 @@ led.enable(false)
|
|||||||
|
|
||||||
### See Also
|
### 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), [enabled](/reference/led/enable)
|
[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),
|
||||||
|
[plotBrightness](/reference/led/plotBrightness),
|
||||||
|
69
docs/reference/led/plotBrightness.md
Normal file
69
docs/reference/led/plotBrightness.md
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# Plot Brightness
|
||||||
|
|
||||||
|
Turn on a LED light with a specific brightness on the [LED screen](/device/screen).
|
||||||
|
|
||||||
|
```sig
|
||||||
|
led.plotBrightness(0,0, 128);
|
||||||
|
```
|
||||||
|
|
||||||
|
## ~hint
|
||||||
|
|
||||||
|
Use [unplot](/reference/led/unplot) to turn **off** an LED.
|
||||||
|
|
||||||
|
## ~
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
* ``x`` is a [number](/types/number) that means the
|
||||||
|
horizontal spot on the LED screen (from left to right: 0, 1, 2, 3,
|
||||||
|
or 4)
|
||||||
|
* ``y`` is a [number](/types/number) that means the vertical
|
||||||
|
spot on the LED screen (from top to bottom: 0, 1, 2, 3, or 4)
|
||||||
|
* ``brightness` is a [number](/types/number) that represents the brightness of the LED, from 0 (off) to 255 (full brightness)
|
||||||
|
|
||||||
|
If a parameter is [out of bounds](/reference/out-of-bounds) (a value
|
||||||
|
other than 0 to 4), then this function will do nothing.
|
||||||
|
|
||||||
|
### ~hint
|
||||||
|
|
||||||
|
The LED screen is a solid square of LEDs with five LEDs on each side.
|
||||||
|
To learn more about how you number the LEDs with ``x`` and ``y``
|
||||||
|
coordinates, see [LED screen](/device/screen).
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
### Example: One LED
|
||||||
|
|
||||||
|
This program turns on the bottom right LED at 50% brightness
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
led.plot(4, 4, 128)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Example: Square
|
||||||
|
|
||||||
|
This program uses a [for loop](/blocks/loops/for)
|
||||||
|
and the `plotBrightness` function
|
||||||
|
to make a square around the edges of the LED screen.
|
||||||
|
|
||||||
|
```blocks
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
led.plot(0, i, 64)
|
||||||
|
led.plot(4, i, 128)
|
||||||
|
led.plot(i, 0, 172)
|
||||||
|
led.plot(i, 4, 255)
|
||||||
|
basic.pause(500)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### ~hint
|
||||||
|
|
||||||
|
Use the [point](/reference/led/point) function to find out if an LED is
|
||||||
|
on or off.
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
|
### See also
|
||||||
|
|
||||||
|
[plot](/reference/led/plot), [unplot](/reference/led/unplot), [point](/reference/led/point), [LED screen](/device/screen)
|
@ -156,8 +156,12 @@
|
|||||||
"led.plotBarGraph": "Displays a vertical bar graph based on the `value` and `high` value.\nIf `high` is 0, the chart gets adjusted automatically.",
|
"led.plotBarGraph": "Displays a vertical bar graph based on the `value` and `high` value.\nIf `high` is 0, the chart gets adjusted automatically.",
|
||||||
"led.plotBarGraph|param|high": "maximum value. If 0, maximum value adjusted automatically, eg: 0",
|
"led.plotBarGraph|param|high": "maximum value. If 0, maximum value adjusted automatically, eg: 0",
|
||||||
"led.plotBarGraph|param|value": "current value to plot",
|
"led.plotBarGraph|param|value": "current value to plot",
|
||||||
"led.plot|param|x": "TODO",
|
"led.plotBrightness": "Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.",
|
||||||
"led.plot|param|y": "TODO",
|
"led.plotBrightness|param|brightness": "the brightness from 0 (off) to 255 (bright), eg:255",
|
||||||
|
"led.plotBrightness|param|x": "the horizontal coordinate of the LED starting at 0",
|
||||||
|
"led.plotBrightness|param|y": "the vertical coordinate of the LED starting at 0",
|
||||||
|
"led.plot|param|x": "the horizontal coordinate of the LED starting at 0",
|
||||||
|
"led.plot|param|y": "the vertical coordinate of the LED starting at 0",
|
||||||
"led.point": "Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.",
|
"led.point": "Get the on/off state of the specified LED using x, y coordinates. (0,0) is upper left.",
|
||||||
"led.point|param|x": "TODO",
|
"led.point|param|x": "TODO",
|
||||||
"led.point|param|y": "TODO",
|
"led.point|param|y": "TODO",
|
||||||
|
@ -264,6 +264,7 @@
|
|||||||
"led.brightness|block": "brightness",
|
"led.brightness|block": "brightness",
|
||||||
"led.enable|block": "led enable %on",
|
"led.enable|block": "led enable %on",
|
||||||
"led.plotBarGraph|block": "plot bar graph of %value |up to %high",
|
"led.plotBarGraph|block": "plot bar graph of %value |up to %high",
|
||||||
|
"led.plotBrightness|block": "plot|x %x|y %y|value %brightness",
|
||||||
"led.plot|block": "plot|x %x|y %y",
|
"led.plot|block": "plot|x %x|y %y",
|
||||||
"led.point|block": "point|x %x|y %y",
|
"led.point|block": "point|x %x|y %y",
|
||||||
"led.setBrightness|block": "set brightness %value",
|
"led.setBrightness|block": "set brightness %value",
|
||||||
|
@ -13,15 +13,34 @@ namespace led {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
||||||
* @param x TODO
|
* @param x the horizontal coordinate of the LED starting at 0
|
||||||
* @param y TODO
|
* @param y the vertical coordinate of the LED starting at 0
|
||||||
*/
|
*/
|
||||||
//% help=led/plot weight=78
|
//% help=led/plot weight=78
|
||||||
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
|
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
|
||||||
//% parts="ledmatrix"
|
//% parts="ledmatrix"
|
||||||
//% x.min=0 x.max=4 y.min=0 y.max=4
|
//% x.min=0 x.max=4 y.min=0 y.max=4
|
||||||
void plot(int x, int y) {
|
void plot(int x, int y) {
|
||||||
uBit.display.image.setPixelValue(x, y, 1);
|
uBit.display.image.setPixelValue(x, y, 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
||||||
|
* @param x the horizontal coordinate of the LED starting at 0
|
||||||
|
* @param y the vertical coordinate of the LED starting at 0
|
||||||
|
* @param brightness the brightness from 0 (off) to 255 (bright), eg:255
|
||||||
|
*/
|
||||||
|
//% help=led/plot weight=78
|
||||||
|
//% blockId=device_plot_brightness block="plot|x %x|y %y|value %brightness" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
|
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
|
||||||
|
//% advanced=true
|
||||||
|
void plotBrightness(int x, int y, int brightness) {
|
||||||
|
brightness = max(0, min(0xff, brightness));
|
||||||
|
// enable greyscale as needed
|
||||||
|
if (brightness != 0 && brightness != 0xff && uBit.display.getDisplayMode() != DISPLAY_MODE_GREYSCALE)
|
||||||
|
uBit.display.setDisplayMode(DISPLAY_MODE_GREYSCALE);
|
||||||
|
uBit.display.image.setPixelValue(x, y, brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
17
libs/core/shims.d.ts
vendored
17
libs/core/shims.d.ts
vendored
@ -441,8 +441,8 @@ declare namespace led {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
* Turn on the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
||||||
* @param x TODO
|
* @param x the horizontal coordinate of the LED starting at 0
|
||||||
* @param y TODO
|
* @param y the vertical coordinate of the LED starting at 0
|
||||||
*/
|
*/
|
||||||
//% help=led/plot weight=78
|
//% help=led/plot weight=78
|
||||||
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
|
//% blockId=device_plot block="plot|x %x|y %y" blockGap=8
|
||||||
@ -450,6 +450,19 @@ declare namespace led {
|
|||||||
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::plot
|
//% x.min=0 x.max=4 y.min=0 y.max=4 shim=led::plot
|
||||||
function plot(x: number, y: number): void;
|
function plot(x: number, y: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn on the specified LED with specific brightness using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
||||||
|
* @param x the horizontal coordinate of the LED starting at 0
|
||||||
|
* @param y the vertical coordinate of the LED starting at 0
|
||||||
|
* @param brightness the brightness from 0 (off) to 255 (bright), eg:255
|
||||||
|
*/
|
||||||
|
//% help=led/plot weight=78
|
||||||
|
//% blockId=device_plot_brightness block="plot|x %x|y %y|value %brightness" blockGap=8
|
||||||
|
//% parts="ledmatrix"
|
||||||
|
//% x.min=0 x.max=4 y.min=0 y.max=4 brightness.min=0 brightness.max=255
|
||||||
|
//% advanced=true shim=led::plotBrightness
|
||||||
|
function plotBrightness(x: number, y: number, brightness: number): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
* Turn off the specified LED using x, y coordinates (x is horizontal, y is vertical). (0,0) is upper left.
|
||||||
* @param x TODO
|
* @param x TODO
|
||||||
|
@ -273,7 +273,16 @@ namespace pxsim.basic {
|
|||||||
|
|
||||||
namespace pxsim.led {
|
namespace pxsim.led {
|
||||||
export function plot(x: number, y: number) {
|
export function plot(x: number, y: number) {
|
||||||
board().ledMatrixState.image.set(x, y, 255);
|
board().ledMatrixState.image.set(x, y, 0xff);
|
||||||
|
runtime.queueDisplayUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function plotBrightness(x: number, y: number, brightness: number) {
|
||||||
|
const state = board().ledMatrixState;
|
||||||
|
brightness = Math.max(0, Math.min(0xff, brightness));
|
||||||
|
if (brightness != 0 && brightness != 0xff && state.displayMode != DisplayMode.greyscale)
|
||||||
|
state.displayMode = DisplayMode.greyscale;
|
||||||
|
state.image.set(x, y, brightness);
|
||||||
runtime.queueDisplayUpdate()
|
runtime.queueDisplayUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user