Skip to content

Commit 4c93d8b

Browse files
committed
Add in Microbit code, tidy files, add README
1 parent 956fc16 commit 4c93d8b

File tree

8 files changed

+94
-0
lines changed

8 files changed

+94
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Intro
2+
3+
An experiment to use Microbits to control MIDI devices.
4+
5+
One Microbit acts as a [receiver](microbit/js/receiver.js) for others that [transmit](microbit/js/transmitter.js) values over radio. It relays these to the serial bus (USB)
6+
7+
These are picked up by a Ruby [programme](ruby/src/microbit-reader.rb) and converted to MIDI controller values hardcoded for a Novation Bass Station synth and sent
8+
9+
# Setup
10+
11+
## Microbit
12+
13+
You need 2 of these.
14+
15+
Paste the code for the Transmitter into the [editor](https://makecode.microbit.org/#editor)
16+
and download this to your Microbit.
17+
18+
Repeat for the Receiver and leave this one connected. Connect the Transmitter to a set of batteries.
19+
20+
## Ruby
21+
22+
Run `cd ruby && bundle install` to add the required Gems.
23+
24+
In the ruby directory, run `ruby src/microbit-reader.rb` and chose a MIDI output (you need one of these). If you move your Transmitter Microbit around, it will output the values it maps to the MIDI controllers and send to your synth.
25+
26+
# TODO
27+
28+
- Make the buttons and gestures do something.
29+
- Make synth agnostic (configurable mapping of controls, e.g. 'learn')
30+
- Allow ranges to be set for controllers, e.g. so we can restrict resonance, etc.
31+
- Make Microbit transmit without 'throttling' - do this in the ruby code (was done to reduce sensitivity)

microbit/js/receiver.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Simple Microbit programme to act as a reciever
2+
// - streams radio packets from other Microbits to
3+
// the serial output (which is USB)
4+
5+
radio.onReceivedValue(function (name, value) {
6+
radio.writeReceivedPacketToSerial()
7+
})
8+
radio.onReceivedString(function (receivedString) {
9+
radio.writeReceivedPacketToSerial()
10+
})
11+
basic.showIcon(IconNames.Pitchfork)
12+
radio.setGroup(1)

microbit/js/transmitter.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// JavaScript for a Microbit to transmit it's orientation
2+
// and other input values via Radio to another Microbit
3+
4+
function compare(current: number, previous: number) {
5+
return Math.floor(current / 2.0) != Math.floor(previous / 2.0)
6+
}
7+
input.onButtonPressed(Button.A, function () {
8+
radio.sendString("input: A")
9+
})
10+
input.onButtonPressed(Button.B, function () {
11+
radio.sendString("input: A")
12+
})
13+
input.onButtonPressed(Button.AB, function () {
14+
radio.sendString("input: AB")
15+
})
16+
input.onGesture(Gesture.Shake, function () {
17+
radio.sendString("input: shake")
18+
})
19+
let lastCompass = 0
20+
let compass = 0
21+
let lastRoll = 0
22+
let roll = 0
23+
let lastPitch = 0
24+
let pitch = 0
25+
basic.showLeds(`
26+
. . # . .
27+
. # # # .
28+
# . # . #
29+
. . # . .
30+
. . # . .
31+
`)
32+
radio.setGroup(1)
33+
radio.setTransmitSerialNumber(true)
34+
basic.forever(function () {
35+
pitch = input.rotation(Rotation.Pitch)
36+
if (compare(pitch, lastPitch)) {
37+
radio.sendValue("pitch", pitch)
38+
lastPitch = pitch
39+
}
40+
roll = input.rotation(Rotation.Roll)
41+
if (compare(roll, lastRoll)) {
42+
radio.sendValue("roll", roll)
43+
lastRoll = roll
44+
}
45+
compass = input.compassHeading()
46+
if (compare(compass, lastCompass)) {
47+
radio.sendValue("compass", compass)
48+
lastCompass = compass
49+
}
50+
basic.pause(100)
51+
})
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)