-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in Microbit code, tidy files, add README
- Loading branch information
Showing
8 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Intro | ||
|
||
An experiment to use Microbits to control MIDI devices. | ||
|
||
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) | ||
|
||
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 | ||
|
||
# Setup | ||
|
||
## Microbit | ||
|
||
You need 2 of these. | ||
|
||
Paste the code for the Transmitter into the [editor](https://makecode.microbit.org/#editor) | ||
and download this to your Microbit. | ||
|
||
Repeat for the Receiver and leave this one connected. Connect the Transmitter to a set of batteries. | ||
|
||
## Ruby | ||
|
||
Run `cd ruby && bundle install` to add the required Gems. | ||
|
||
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. | ||
|
||
# TODO | ||
|
||
- Make the buttons and gestures do something. | ||
- Make synth agnostic (configurable mapping of controls, e.g. 'learn') | ||
- Allow ranges to be set for controllers, e.g. so we can restrict resonance, etc. | ||
- Make Microbit transmit without 'throttling' - do this in the ruby code (was done to reduce sensitivity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Simple Microbit programme to act as a reciever | ||
// - streams radio packets from other Microbits to | ||
// the serial output (which is USB) | ||
|
||
radio.onReceivedValue(function (name, value) { | ||
radio.writeReceivedPacketToSerial() | ||
}) | ||
radio.onReceivedString(function (receivedString) { | ||
radio.writeReceivedPacketToSerial() | ||
}) | ||
basic.showIcon(IconNames.Pitchfork) | ||
radio.setGroup(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// JavaScript for a Microbit to transmit it's orientation | ||
// and other input values via Radio to another Microbit | ||
|
||
function compare(current: number, previous: number) { | ||
return Math.floor(current / 2.0) != Math.floor(previous / 2.0) | ||
} | ||
input.onButtonPressed(Button.A, function () { | ||
radio.sendString("input: A") | ||
}) | ||
input.onButtonPressed(Button.B, function () { | ||
radio.sendString("input: A") | ||
}) | ||
input.onButtonPressed(Button.AB, function () { | ||
radio.sendString("input: AB") | ||
}) | ||
input.onGesture(Gesture.Shake, function () { | ||
radio.sendString("input: shake") | ||
}) | ||
let lastCompass = 0 | ||
let compass = 0 | ||
let lastRoll = 0 | ||
let roll = 0 | ||
let lastPitch = 0 | ||
let pitch = 0 | ||
basic.showLeds(` | ||
. . # . . | ||
. # # # . | ||
# . # . # | ||
. . # . . | ||
. . # . . | ||
`) | ||
radio.setGroup(1) | ||
radio.setTransmitSerialNumber(true) | ||
basic.forever(function () { | ||
pitch = input.rotation(Rotation.Pitch) | ||
if (compare(pitch, lastPitch)) { | ||
radio.sendValue("pitch", pitch) | ||
lastPitch = pitch | ||
} | ||
roll = input.rotation(Rotation.Roll) | ||
if (compare(roll, lastRoll)) { | ||
radio.sendValue("roll", roll) | ||
lastRoll = roll | ||
} | ||
compass = input.compassHeading() | ||
if (compare(compass, lastCompass)) { | ||
radio.sendValue("compass", compass) | ||
lastCompass = compass | ||
} | ||
basic.pause(100) | ||
}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.