module main author unknown version 1 0 description '' variables 'speed 1' 'speed 2' script 66 66 { whenStarted forever { if ('[radio:messageReceived]') { if (('[data:find]' 'A' ('[radio:receivedString]')) > 0) { 'speed 1' = -100 } else { 'speed 1' = 0 } if (('[data:find]' 'B' ('[radio:receivedString]')) > 0) { 'speed 2' = 100 } else { 'speed 2' = 0 } } } } script 404 68 { whenStarted 'speed 1' = 0 'speed 2' = 0 forever { setServoSpeed 1 (v 'speed 1') setServoSpeed 2 (v 'speed 2') } } module 'Basic Sensors' Input author MicroBlocks version 1 0 tags tilt acceleration light sensor description 'Provides blocks to read tilt in the three axes, acceleration, temperature and light level. Many boards come with this particular set of sensors, such as the micro:bit, the Circuit Playground Express, the Calliope or the Citilab ED1.' spec 'r' '[sensors:tiltX]' 'tilt x' spec 'r' '[sensors:tiltY]' 'tilt y' spec 'r' '[sensors:tiltZ]' 'tilt z' spec 'r' '[sensors:acceleration]' 'acceleration' spec 'r' '[display:lightLevel]' 'light level' spec 'r' '[sensors:temperature]' 'temperature (°C)' module 'LED Display' Output author MicroBlocks version 1 1 tags pixel matrix led tft 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) also support this primitives in a simulated "fat pixel" display.' spec ' ' '[display:mbDisplay]' 'display _' 'microbitDisplay' 15237440 spec ' ' '[display:mbDisplayOff]' 'clear display' spec ' ' '[display:mbPlot]' 'plot x _ y _' 'num num' 3 3 spec ' ' '[display:mbUnplot]' 'unplot x _ y _' 'num num' 3 3 spec ' ' 'displayCharacter' 'display character _' 'str' 'A' to displayCharacter s { s = ('[data:join]' '' s) if ((size s) == 0) { '[display:mbDisplayOff]' return 0 } '[display:mbDrawShape]' ('[display:mbShapeForLetter]' (at 1 s)) } module Radio Comm author MicroBlocks version 1 1 tags radio communication messaging network description 'Send and receive messages between micro:bit boards via their built-in radio system.' spec ' ' '[radio:sendInteger]' 'radio send number _' 'num' 123 spec ' ' '[radio:sendString]' 'radio send string _' 'str' 'Hello!' spec ' ' '[radio:sendPair]' 'radio send pair _ = _' 'str num' 'light' 10 spec 'r' '[radio:messageReceived]' 'radio message received?' spec 'r' '[radio:receivedInteger]' 'radio last number' spec 'r' '[radio:receivedString]' 'radio last string' spec ' ' '[radio:setGroup]' 'radio set group _ (0-255)' 'num' 0 spec ' ' '[radio:setPower]' 'radio set power (0-7) _' 'num' 4 spec 'r' '_receivedMessageType' '_radio last message type' spec ' ' '_setChannel' '_radio set channel (0-83) _' 'num' 7 spec 'r' '_signalStrength' '_radio last signal strength' to '_receivedMessageType' { return ('[radio:receivedMessageType]') } to '_setChannel' channel { '[radio:setChannel]' channel } to '_signalStrength' { return ('[radio:signalStrength]') } module Servo Output author MicroBlocks version 1 0 tags servo motor angle rotation position description 'Control both positional (angle) and rotational servo motors.' variables _servoPin _servoPulseWidth spec ' ' 'setServoAngle' 'set servo _ to _ degrees (-90 to 90)' 'num num' 1 90 spec ' ' 'setServoSpeed' 'set servo _ to speed _ (-100 to 100)' 'num num' 1 100 spec ' ' 'stopServo' 'stop servo _' 'num' 1 spec 'r' '_servoIndex' '_servoIndex _' 'num' 1 spec ' ' '_servoPulse' '_servoPulse pin _ usecs _' 'num num' 1 1500 spec ' ' '_servoUpdateLoop' '_servoUpdateLoop' to '_servoIndex' which { if (_servoPin == 0) { _servoPin = ('[data:makeList]') _servoPulseWidth = ('[data:makeList]') sendBroadcast '_servoUpdateLoop' } local 'i' ('[data:find]' which _servoPin) if (i < 0) { comment 'Add new pin' '[data:addLast]' which _servoPin '[data:addLast]' '1500' _servoPulseWidth i = (size _servoPin) } return i } to '_servoPulse' pin usecs { if (usecs == 0) { comment 'Servo stopped; do nothing' return 0 } usecs = (maximum 850 (minimum usecs 2150)) comment 'Split wait into a long wait followed by a wait of <= 30 usecs for greater accuracy' local 'endTime' ((microsOp) + usecs) digitalWriteOp pin true waitMicros (usecs - 30) waitMicros (endTime - (microsOp)) digitalWriteOp pin false } to '_servoUpdateLoop' { forever { if (_servoPin != 0) { comment 'If the _servoPin list is not 0, update the servos' for i (size _servoPin) { local 'pin' (at i _servoPin) local 'usecs' (at i _servoPulseWidth) if (and (pin >= 0) (usecs != 0)) { '_servoPulse' pin usecs } } waitMillis 15 } } } to setServoAngle which degrees optionalReverse { local 'reversed' false if ((pushArgCount) > 2) { reversed = optionalReverse } if reversed { degrees = (0 - degrees) } local 'pulseWidth' (1500 - (10 * degrees)) if ('[io:hasServo]') { '[io:setServo]' which pulseWidth } else { atPut ('_servoIndex' which) _servoPulseWidth pulseWidth } } to setServoSpeed which speed optionalReverse { local 'reversed' false if ((pushArgCount) > 2) { reversed = optionalReverse } if reversed { speed = (0 - speed) } local 'pulseWidth' (1500 - (10 * speed)) if ((absoluteValue speed) < 2) { pulseWidth = 0 } if ('[io:hasServo]') { '[io:setServo]' which pulseWidth } else { atPut ('_servoIndex' which) _servoPulseWidth pulseWidth } } to stopServo which { if ('[io:hasServo]') { '[io:setServo]' which 0 } else { atPut ('_servoIndex' which) _servoPulseWidth 0 } }