module main author 'Pablo Moraga' version 1 0 description 'Decenas y unidades' variables numero script 50 50 { whenStarted numero = 0 } script 470 50 { whenButtonPressed 'A' numero += 10 displayCharacter 'D' } script 50 370 { whenButtonPressed 'B' numero += 1 displayCharacter 'U' } script 470 370 { whenCondition (touchPin_logoTouched) scroll_text numero } script 50 690 { whenButtonPressed 'A+B' numero = 0 scroll_text numero } module 'LED Display' Output author MicroBlocks version 1 15 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' advanced spec ' ' 'set display color' 'set display color _' 'color' spec 'r' 'led_image' 'LED image #BR# _' 'microbitDisplay' 15237440 space spec 'r' '_led_namedImage' '_led_namedImage _' 'menu.led_imageMenu' 'happy' spec 'r' '_led_imageData' '_led_imageData' 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 displayCharacter s { s = ('[data:join]' '' s) if ((size s) == 0) { '[display:mbDisplayOff]' return 0 } '[display:mbDrawShape]' ('[display:mbShapeForLetter]' (at 1 s)) 1 1 } 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 led_image twentyFiveBitInt { comment 'An LED image is a 25-bit integer' return twentyFiveBitInt } 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) } } (or ('KidsIOT' == (boardType)) ('CodingBox' == (boardType))) { for position (((size text) * 6) + 21) { if _stop_scrolling_text {return 0} '[tft:deferUpdates]' '[tft:clear]' '[tft:text]' text (128 - (6 * position)) 6 (colorSwatch 255 255 255 255) 6 false '[tft:resumeUpdates]' waitMillis (delay / 8) } } 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 'set display color' color { '[display:mbSetColor]' color } to stopScrollingText { _stop_scrolling_text = (booleanConstant true) waitMillis 10 '[display:mbDisplayOff]' } module TouchPin Input author MicroBlocks version 1 0 description 'Capacitive pin touch sensing for micro:bit, Calliope mini, and other boards with touch pins. Works with pins that have 1M ohm external pullup resistors. ' variables _touchPin_isTouched _touchPin_releaseCount spec 'r' 'touchPin_pinTouched' 'pin _ touched' 'num' 0 spec 'r' 'touchPin_logoTouched' 'logo touched' to touchPin_logoTouched { if ('micro:bit v2' == (boardType)) { return (touchPin_pinTouched 26) } ('Calliope v3' == (boardType)) { return (touchPin_pinTouched 26) } return (booleanConstant false) } to touchPin_pinTouched pin { local 'threshold' 20 comment 'Discharge pin' digitalWriteOp pin false waitMillis 5 local 'n' 0 comment 'Wait for pin to become high, incrementing n' repeatUntil (digitalReadOp pin) { n += 1 if (n >= threshold) { comment 'Long charging time means pin is touched' _touchPin_isTouched = (booleanConstant true) _touchPin_releaseCount = 0 digitalWriteOp pin false return _touchPin_isTouched } } digitalWriteOp pin false if (_touchPin_isTouched == 0) { _touchPin_isTouched = (booleanConstant false) } comment 'count is < threshold so pin not touched' if _touchPin_isTouched { comment 'Require several low counts in a row to exit "isTouched" state to avoid jitter.' _touchPin_releaseCount += 1 if (_touchPin_releaseCount > 3) { _touchPin_isTouched = (booleanConstant false) } } return _touchPin_isTouched }