diff --git a/docs/reference/serial.md b/docs/reference/serial.md index 8d8bb992..f88c8250 100644 --- a/docs/reference/serial.md +++ b/docs/reference/serial.md @@ -7,6 +7,7 @@ serial.writeLine(""); serial.writeNumber(0); serial.writeValue("x", 0); serial.writeString(""); +serial.writeNumbers([0]); serial.readUntil(","); serial.readLine(); serial.readString(); @@ -25,7 +26,8 @@ serial.readBuffer(64); ## See Also [writeLine](/reference/serial/write-line), [writeNumber](/reference/serial/write-number), [writeValue](/reference/serial/write-value), -[writeString](/reference/serial/write-string), [readUntil](/reference/serial/read-until), [readLine](/reference/serial/read-line), +[writeString](/reference/serial/write-string), +[writeNumbers](/reference/serial/write-numbers), [readUntil](/reference/serial/read-until), [readLine](/reference/serial/read-line), [readString](/reference/serial/read-string), [onDataReceived](/reference/serial/on-data-received), [redirect](/reference/serial/redirect), [writeBuffer](/reference/serial/write-buffer), [readBuffer](/reference/serial/read-buffer), [redirectToUSB](/reference/serial/redirect-to-usb) diff --git a/docs/reference/serial/write-number.md b/docs/reference/serial/write-number.md index 624ac459..8e73eacd 100644 --- a/docs/reference/serial/write-number.md +++ b/docs/reference/serial/write-number.md @@ -10,13 +10,13 @@ serial.writeNumber(0); * `value` is the [number](/types/number) to write to the serial port -## Example: one through ten +## Example: one two three -This program repeatedly writes a 10-digit number to the serial port. +This program repeatedly writes a 3-digit number to the serial port. ```blocks basic.forever(() => { - serial.writeNumber(1234567890); + serial.writeNumber(123); basic.pause(5000); }); ``` @@ -37,5 +37,6 @@ basic.forever(() => { [serial](/device/serial), [serial write line](/reference/serial/write-line), -[serial write value](/reference/serial/write-value) +[serial write value](/reference/serial/write-value), +[serial write numbers](/reference/serial/write-numbers) diff --git a/docs/reference/serial/write-numbers.md b/docs/reference/serial/write-numbers.md new file mode 100644 index 00000000..9ddf60d6 --- /dev/null +++ b/docs/reference/serial/write-numbers.md @@ -0,0 +1,39 @@ +# Serial Write Numbers + +Write an array of numbers to the [serial](/device/serial) port. + +```sig +serial.writeNumbers([0, 1, 2]); +``` + +## Parameters + +* `values` is the array of [number](/types/number) to write to the serial port + +## Example: one two three + +This program repeatedly writes a 3-number array to the serial port. + +```blocks +basic.forever(() => { + serial.writeNumbers([1, 2, 3]); + basic.pause(5000); +}); +``` + +## Example: plot temperature and light + + +```blocks +serial.writeLine("temp,light") +basic.forever(() => { + serial.writeNumbers([input.temperature(), input.lightLevel()]) +}) +``` + +## See also + +[serial](/device/serial), +[serial write line](/reference/serial/write-line), +[serial write value](/reference/serial/write-value) + diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 5eb021d7..8cdc38ed 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -154,7 +154,7 @@ "control.eventValue": "Gets the value of the last event executed on the bus", "control.eventValueId": "Returns the value of a C++ runtime constant", "control.inBackground": "Schedules code that run in the background.", - "control.onEvent": "Raises an event in the event bus.", + "control.onEvent": "Registers an event handler.", "control.panic": "Display specified error code and stop the program.", "control.raiseEvent": "Raises an event in the event bus.", "control.raiseEvent|param|mode": "optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).", @@ -426,6 +426,7 @@ "serial.writeBuffer": "Sends a buffer through Serial connection", "serial.writeLine": "Prints a line of text to the serial", "serial.writeNumber": "Prints a numeric value to the serial", + "serial.writeNumbers": "Prints an array of numeric values to the serial as CSV", "serial.writeString": "Sends a piece of text through Serial connection.", "serial.writeValue": "Writes a ``name: value`` pair line to the serial.", "serial.writeValue|param|name": "name of the value stream, eg: x", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 8c24f7dc..1649ba28 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -343,6 +343,7 @@ "serial.redirect|block": "serial|redirect to|TX %tx|RX %rx|at baud rate %rate", "serial.writeBuffer|block": "serial|write buffer %buffer", "serial.writeLine|block": "serial|write line %text", + "serial.writeNumbers|block": "serial|write numbers %values", "serial.writeNumber|block": "serial|write number %value", "serial.writeString|block": "serial|write string %text", "serial.writeValue|block": "serial|write value %name|= %value", diff --git a/libs/core/serial.cpp b/libs/core/serial.cpp index b201660a..ed3c13c2 100644 --- a/libs/core/serial.cpp +++ b/libs/core/serial.cpp @@ -101,7 +101,7 @@ namespace serial { * Sends a piece of text through Serial connection. */ //% help=serial/write-string - //% weight=87 + //% weight=87 blockGap=8 //% blockId=serial_writestring block="serial|write string %text" void writeString(StringData *text) { if (!text) return; diff --git a/libs/core/serial.ts b/libs/core/serial.ts index beb41259..9b08fc24 100644 --- a/libs/core/serial.ts +++ b/libs/core/serial.ts @@ -32,6 +32,21 @@ namespace serial { writeString(value.toString()); } + /** + * Prints an array of numeric values to the serial as CSV + */ + //% help=serial-write-numbers + //% weight=86 + //% blockId=serial_writenumbers block="serial|write numbers %values" + export function writeNumbers(values: number[]): void { + if (!values) return; + for(let i = 0; i < values.length; ++i) { + if (i > 0) writeString(","); + writeNumber(values[i]); + } + writeLine("") + } + /** * Writes a ``name: value`` pair line to the serial. * @param name name of the value stream, eg: x diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index e54e69c8..03842d13 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -404,7 +404,7 @@ declare namespace control { function raiseEvent(src: number, value: number, mode?: EventCreationMode): void; /** - * Raises an event in the event bus. + * Registers an event handler. */ //% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id" //% help=control/on-event @@ -800,7 +800,7 @@ declare namespace serial { * Sends a piece of text through Serial connection. */ //% help=serial/write-string - //% weight=87 + //% weight=87 blockGap=8 //% blockId=serial_writestring block="serial|write string %text" shim=serial::writeString function writeString(text: string): void; diff --git a/package.json b/package.json index a93c3032..073cf372 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,6 @@ "semantic-ui-less": "^2.2.4" }, "dependencies": { - "pxt-core": "0.17.13" + "pxt-core": "0.17.14" } }