2.1.28, initiation update to PXT v5.28.24 (#54)

This commit is contained in:
Amerlander
2019-12-02 05:58:26 +01:00
committed by Peli de Halleux
parent 38a964516e
commit 5c114a0c57
1261 changed files with 50692 additions and 21604 deletions

View File

@@ -16,22 +16,28 @@
* @param high maximum value. If 0, maximum value adjusted automatically, eg: 0
*/
//% help=led/plot-bar-graph weight=20
//% blockId=device_plot_bar_graph block="plot bar graph of %value |up to %high" icon="\uf080" blockExternalInputs=true
//% blockId=device_plot_bar_graph block="plot bar graph of %value up to %high" icon="\uf080" blockExternalInputs=true
//% parts="ledmatrix"
export function plotBarGraph(value: number, high: number): void {
let now = input.runningTime();
serial.writeString(value.toString() + "\r\n");
const now = input.runningTime();
console.logValue("", value);
value = Math.abs(value);
if (high != 0) barGraphHigh = high;
else if (value > barGraphHigh || now - barGraphHighLast > 10000) {
// auto-scale "high" is not provided
if (high > 0) {
barGraphHigh = high;
} else if (value > barGraphHigh || now - barGraphHighLast > 10000) {
barGraphHigh = value;
barGraphHighLast = now;
}
barGraphHigh = Math.max(barGraphHigh, 16);
// normalize lack of data to 0..1
if (barGraphHigh < 16 * Number.EPSILON)
barGraphHigh = 1;
let v = (value * 15) / barGraphHigh;
// normalize value to 0..1
const v = value / barGraphHigh;
const dv = 1 / 16;
let k = 0;
for (let y = 4; y >= 0; --y) {
for (let x = 0; x < 3; ++x) {
@@ -42,19 +48,21 @@
plot(2 - x, y);
plot(2 + x, y);
}
++k;
k += dv;
}
}
}
/**
* Toggles a particular pixel
* @param x TODO
* @param y TODO
* @param x pixel column
* @param y pixel row
*/
//% help=led/toggle weight=77
//% blockId=device_led_toggle block="toggle|x %x|y %y" icon="\uf204" blockGap=8
//% parts="ledmatrix"
//% x.min=0 x.max=4 y.min=0 y.max=4
//% x.fieldOptions.precision=1 y.fieldOptions.precision=1
export function toggle(x: number, y: number): void {
if (led.point(x, y)) {
led.unplot(x, y);
@@ -91,7 +99,7 @@
/**
* Fades in the screen display.
* @param ms TODO
* @param ms fade time in milleseconds
*/
//% help=led/fade-in
//% parts="ledmatrix"
@@ -114,7 +122,7 @@
/**
* Fades out the screen brightness.
* @param ms TODO
* @param ms fade time in milliseconds
*/
//% help=led/fade-out
//% parts="ledmatrix"