module main author unknown version 1 0 description '' variables wait script 521 146 { whenBroadcastReceived '' wait = (getLastBroadcast) } script 205 151 { whenStarted wait = 500 forever { led_displayImage 'small heart' waitMillis wait led_displayImage 'heart' waitMillis wait } } module 'LED Display' Output author MicroBlocks version 1 8 choices led_imageMenu heart 'small heart' yes no happy sad confused angry asleep surprised silly fabulous meh 't-shirt' 'roller skate' duck house tortoise butterfly 'stick figure' ghost sword giraffe skull umbrella snake rabbit cow 'quarter note' 'eight note' pitchfork target triangle 'left triangle' 'chess board' diamond 'small diamond' square 'small square' scissors description 'Display primitives for the 5x5 LED display on the BBC micro:bit, Calliope mini and M5Atom Matrix. Boards with TFT displays (such as the Citilab ED1 or the M5Stack family) support these primitives with a simulated "fat pixel" display.' variables _stop_scrolling_text spec ' ' '[display:mbDisplay]' 'display _' 'microbitDisplay' 15237440 spec ' ' 'led_displayImage' 'display image _ : x _ y _' 'menu.led_imageMenu num num' 'happy' 1 1 spec ' ' '[display:mbDisplayOff]' 'clear display' space spec ' ' '[display:mbPlot]' 'plot x _ y _' 'num num' 3 3 spec ' ' '[display:mbUnplot]' 'unplot x _ y _' 'num num' 3 3 space spec ' ' 'displayCharacter' 'display character _' 'str' 'A' spec ' ' 'scroll_text' 'scroll text _ : pausing _ ms' 'str num' 'HELLO ROSA!' 100 spec ' ' 'stopScrollingText' 'stop scrolling' space spec ' ' '_set display color' 'set display color _' 'color' space spec 'r' '_led_image' 'led image _' 'microbitDisplay' 15237440 spec 'r' '_led_namedImage' '_led_namedImage _' 'menu.led_imageMenu' 'happy' spec 'r' '_led_imageData' '_led_imageData' to '_led_image' twentyFiveBitInt { comment 'An LED image is a 25-bit integer' return twentyFiveBitInt } to '_led_imageData' { return 'heart:4685802,small heart:145728,yes:2269696,no:18157905,happy:15237440,sad:18284864,confused:22348096,angry:23036241,asleep:459616,surprised:4526090,silly:25984017,fabulous:15008639,meh:2236443,t-shirt:15154043,roller skate:11534104,duck:489702,house:10976708,tortoise:359872,butterfly:29332475,stick figure:18158564,ghost:23068334,sword:4657284,giraffe:10946627,skull:15171246,umbrella:6460398,snake:469859,rabbit:16104613,cow:4685361,quarter note:7573636,eight note:7590276,pitchfork:4357813,target:4681156,triangle:1026176,left triangle:32805985,chess board:11184810,diamond:4539716,small diamond:141440,square:33080895,small square:469440,scissors:20287859,' } to '_led_namedImage' name { local 'data' ('_led_imageData') local 'i' ('[data:find]' name data) if (i == -1) { comment 'Name not found' return 0 } local 'start' (('[data:find]' ':' data i) + 1) local 'end' (('[data:find]' ',' data i) - 1) return ('[data:convertType]' ('[data:copyFromTo]' data start end) 'number') } to '_set display color' color { callCustomCommand '[display:mbSetColor]' ('[data:makeList]' color) } to displayCharacter s { s = ('[data:join]' '' s) if ((size s) == 0) { '[display:mbDisplayOff]' return 0 } '[display:mbDrawShape]' ('[display:mbShapeForLetter]' (at 1 s)) } to led_displayImage imageName optionalX optionalY { local 'image' imageName if (isType image 'string') { image = ('_led_namedImage' imageName) } '[display:mbDrawShape]' image (argOrDefault 2 1) (argOrDefault 3 1) } to scroll_text text optionalDelay { text = ('[data:join]' '' text) local 'delay' 100 if ((pushArgCount) > 1) { delay = optionalDelay } _stop_scrolling_text = (booleanConstant false) if ('Pico:ed' == (boardType)) { for position (((size text) * 6) + 18) { if _stop_scrolling_text {return 0} '[display:mbDisplayOff]' '[tft:text]' text (17 - position) 0 (colorSwatch 125 125 125 255) 1 true waitMillis (delay / 2) } } else { for position (((size text) * 6) + 6) { if _stop_scrolling_text {return 0} for i (size text) { '[display:mbDrawShape]' ('[display:mbShapeForLetter]' ('[data:unicodeAt]' i text)) (((i * 6) + 2) - position) 1 } waitMillis delay } } } to stopScrollingText { _stop_scrolling_text = (booleanConstant true) waitMillis 10 '[display:mbDisplayOff]' }