Created
May 20, 2020 00:24
-
-
Save konsumer/18aeb6ea8d9df2204f0c464438017a3b to your computer and use it in GitHub Desktop.
Gamecube controller (or DDR Mat) to USB MIDI. Install "Nintendo" and "MIDIUSB" in arduino library-manager. Use this on a programmable-USB arduino, like Leonardo.
This file contains hidden or 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
| #include "Nintendo.h" | |
| #include "MIDIUSB.h" | |
| // attach gamecube controller red wire on this digital pin | |
| #define GC_PIN 7 | |
| // MIDI controls for each pad | |
| int ctrls[6] = { 10, 11, 12, 13, 14, 15 }; | |
| // track previous state | |
| boolean buttonsPrevious[6] = { true, true, true, true, true, true }; | |
| CGamecubeController GamecubeController(GC_PIN); | |
| void controlChange(byte channel, byte control, byte value) { | |
| midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value}; | |
| MidiUSB.sendMIDI(event); | |
| } | |
| void setup() {} | |
| void loop() { | |
| auto report = GamecubeController.getReport(); | |
| boolean buttonsNow[6] = { | |
| report.dup, | |
| report.ddown, | |
| report.dleft, | |
| report.dright, | |
| report.a, | |
| report.b | |
| }; | |
| for (int i = 0; i < 6; i++) { | |
| if (buttonsPrevious[i] != buttonsNow[i]){ | |
| controlChange(1, ctrls[i], buttonsNow[i] ? 127 : 0); | |
| } | |
| buttonsPrevious[i] = buttonsNow[i]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment