Skip to content

Instantly share code, notes, and snippets.

@oschettler
Last active October 11, 2020 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oschettler/9db9f54d4df366bf85896f873a2ff35e to your computer and use it in GitHub Desktop.
Save oschettler/9db9f54d4df366bf85896f873a2ff35e to your computer and use it in GitHub Desktop.
Mood Sync with https://microblocks.fun
module main
author unknown
version 1 0
description ''
script 496 60 {
whenButtonPressed 'B'
'[display:mbDisplay]' 18284864
'[radio:sendString]' 'traurig'
waitMillis 500
'[display:mbDisplayOff]'
}
script 50 61 {
whenButtonPressed 'A'
'[display:mbDisplay]' 15237440
'[radio:sendString]' 'lustig'
waitMillis 500
'[display:mbDisplayOff]'
}
script 332 118 {
whenBroadcastReceived 'traurig'
'[display:mbDisplay]' 18284864
}
script 54 298 {
whenStarted
forever {
if ('[radio:messageReceived]') {sendBroadcast ('[radio:receivedString]')}
}
}
script 332 304 {
whenBroadcastReceived 'lustig'
'[display:mbDisplay]' 15237440
}
script 60 784 {
whenStarted
}
module Calliope
author MicroBlocks
version 1 0
tags calliope led sound speaker
description 'Blocks to control the LED and speaker in Calliope boards.'
spec ' ' 'Calliope set LED' 'Calliope set LED red _ green _ blue _' 'auto auto auto' 0 0 100
spec ' ' 'Calliope set speaker' 'Calliope set speaker _' 'bool' true
spec 'r' 'Calliope sound' 'Calliope loudness'
to 'Calliope set LED' red green blue {
'[display:neoPixelSetPin]' -1 false
local 'rgb' ((((255 * red) / 100) & 255) << 16)
rgb = (rgb | ((((255 * green) / 100) & 255) << 8))
rgb = (rgb | (((255 * blue) / 100) & 255))
'[display:neoPixelSend]' rgb
}
to 'Calliope set speaker' onOff {
digitalWriteOp 23 true
digitalWriteOp 24 onOff
digitalWriteOp 25 (not onOff)
}
to 'Calliope sound' {
local 'min' 10000
local 'max' 0
local 'end_msecs' ((millisOp) + 50)
repeatUntil ((millisOp) > end_msecs) {
local 'sample' (analogReadOp 0)
if (sample < min) {
min = sample
}
if (sample > max) {
max = sample
}
}
return ((100 * (max - min)) / 1020)
}
module 'LED Display' Output
author MicroBlocks
version 1 0
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)
'[display:mbDrawShape]' ('[display:mbShapeForLetter]' (at 1 s))
}
module Radio Comm
author MicroBlocks
version 1 0
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 _' 'num' 0
spec ' ' '[radio:setPower]' 'radio set power (0-7) _' 'num' 4
spec 'r' '_receivedMessageType' '_radio last message type'
spec ' ' '_radio receive packet' '_radio receive packet _' 'str' '32-element list'
spec ' ' '_radio send packet' '_radio send packet _' 'str' '32-element list'
spec 'r' '_signalStrength' '_radio last signal strength'
spec ' ' '_setChannel' '_radio set channel (0-83) _' 'num' 7
to '_radio receive packet' list {
'[radio:packetReceive]' list
}
to '_radio send packet' packet {
'[radio:packetSend]' packet
}
to '_receivedMessageType' {
return ('[radio:receivedMessageType]')
}
to '_setChannel' channel {
'[radio:setChannel]' channel
}
to '_signalStrength' {
return ('[radio:signalStrength]')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment