Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit 13ccfb5

Browse files
authored
Update max7219.ts
1 parent d9a6a71 commit 13ccfb5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

max7219.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace max7219_matrix {
207207
/**
208208
* Print a text accross the chain of MAX7219 matrixs at a specific spot. Offset value -8 ~ last column of matrixs. You can choose to clear the screen or not (if not it can be used to print multiple string on the MAX7219 chain).
209209
*/
210-
//% block="Display text $text|offset $offset|clear screen first $clear" text.defl="Hi!" offset.min=-8 clear.defl=true group="2. Display text on matrixs" blockExternalInputs=true
210+
//% block="Display text (align left) $text|offset $offset|clear screen first $clear" text.defl="Hi!" offset.min=-8 clear.defl=true group="2. Display text on matrixs" blockExternalInputs=true
211211
export function displayText(text: string, offset: number, clear: boolean) {
212212
// clear screen and array if needed
213213
if (clear) {
@@ -252,6 +252,19 @@ namespace max7219_matrix {
252252
matrixCountdown--
253253
}
254254
}
255+
256+
/**
257+
* Print a text on the chain of MAX7219 matrixs and automatically align to the right.
258+
*/
259+
//% block="Display text (align right) $text|clear screen first $clear" text.defl="Hi!" clear.defl=true group="2. Display text on matrixs" blockExternalInputs=true
260+
export function displayTextAlignRight(text: string, clear: boolean) {
261+
let len = 0
262+
for (let i = 0; i < text.length; i++) {
263+
let index = font.indexOf(text.substr(i, 1))
264+
if (index >= 0) len += font_matrix[index].length
265+
}
266+
displayText(text, _matrixNum * 8 - len, clear)
267+
}
255268

256269
/**
257270
* Print a custom character from a number array on the chain of MAX7219 matrixs at a specific spot. Each number in the array is 0-255, the decimal version of column's byte number. Offset value -8 ~ last column of matrixs. You can choose to clear the screen or not (if not it can be used to print multiple string on the MAX7219 chain).

0 commit comments

Comments
 (0)