moving print ports to examples (#288)

This commit is contained in:
Peli de Halleux 2018-01-31 08:44:58 -08:00 committed by GitHub
parent a52ce112dc
commit d548dfb578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 58 deletions

View File

@ -0,0 +1,40 @@
# Print Ports
```typescript
/**
* Print the port states on the screen
*/
//% blockId=brickPrintPorts block="print ports"
//% help=brick/print-ports
//% weight=1 group="Screen"
function printPorts() {
const col = 44;
clearScreen();
function scale(x: number) {
if (Math.abs(x) > 1000) return Math.round(x / 100) / 10 + "k";
return ("" + (x >> 0));
}
// motors
const datas = motors.getAllMotorData();
for(let i = 0; i < datas.length; ++i) {
const data = datas[i];
if (!data.actualSpeed && !data.count) continue;
const x = i * col;
print(`${scale(data.actualSpeed)}%`, x, brick.LINE_HEIGHT)
print(`${scale(data.count)}>`, x, 2 * brick.LINE_HEIGHT)
print(`${scale(data.tachoCount)}|`, x, 3 * brick.LINE_HEIGHT)
}
// sensors
const sis = sensors.internal.getActiveSensors();
for(let i =0; i < sis.length; ++i) {
const si = sis[i];
const x = (si.port() - 1) * col;
const v = si._query();
print(`${scale(v)}`, x, 9 * brick.LINE_HEIGHT)
}
}
```

View File

@ -9,7 +9,6 @@ brick.showString("Hello world!", 1);
brick.showNumber(0, 1);
brick.showValue("item", 0, 1);
brick.clearScreen();
brick.printPorts();
```
## Buttons

View File

@ -1,19 +0,0 @@
# print Ports
Print the status of the ports on the screen.
```sig
brick.printPorts();
```
## Example
Show the port status.
```blocks
brick.printPorts();
```
## See also
[show string](/reference/brick/show-string), [show value](/reference/brick/show-value)

View File

@ -30,7 +30,6 @@
"brick.buttonRight": "Right button on the EV3 Brick.",
"brick.buttonUp": "Up button on the EV3 Brick.",
"brick.clearScreen": "Clear the screen",
"brick.printPorts": "Print the port states on the screen",
"brick.setLight": "Set lights.",
"brick.setLight|param|pattern": "the lights pattern to use. eg: BrickLight.Orange",
"brick.showImage": "Show an image on the screen",

View File

@ -36,7 +36,6 @@
"brick.buttonRight|block": "button right",
"brick.buttonUp|block": "button up",
"brick.clearScreen|block": "clear screen",
"brick.printPorts|block": "print ports",
"brick.setLight|block": "set light to %pattern",
"brick.showImage|block": "show image %image=screen_image_picker",
"brick.showNumber|block": "show number %name|at line %line",

View File

@ -211,40 +211,4 @@ namespace brick {
if (y < y1)
setLineCore(x, x1, y, mode);
}
/**
* Print the port states on the screen
*/
//% blockId=brickPrintPorts block="print ports"
//% help=brick/print-ports
//% weight=1 group="Screen"
export function printPorts() {
const col = 44;
clearScreen();
function scale(x: number) {
if (Math.abs(x) > 1000) return Math.round(x / 100) / 10 + "k";
return ("" + (x >> 0));
}
// motors
const datas = motors.getAllMotorData();
for(let i = 0; i < datas.length; ++i) {
const data = datas[i];
if (!data.actualSpeed && !data.count) continue;
const x = i * col;
print(`${scale(data.actualSpeed)}%`, x, brick.LINE_HEIGHT)
print(`${scale(data.count)}>`, x, 2 * brick.LINE_HEIGHT)
print(`${scale(data.tachoCount)}|`, x, 3 * brick.LINE_HEIGHT)
}
// sensors
const sis = sensors.internal.getActiveSensors();
for(let i =0; i < sis.length; ++i) {
const si = sis[i];
const x = (si.port() - 1) * col;
const v = si._query();
print(`${scale(v)}`, x, 9 * brick.LINE_HEIGHT)
}
}
}