Last active
August 29, 2015 14:21
-
-
Save varlen/2f3f073c63034f199d7b to your computer and use it in GitHub Desktop.
Arduino sketch for (really) minimalist MIDI controller
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
//One Key MIDI Piano | |
//This is a test for Serial MIDI output through Arduino USB port | |
//Used Hairless Midi as Serial->MIDI bridge and one push button on pin 53 of Arduino Mega 2560 | |
//Connect GND|<------{|Button|}------>| Pin 53 | |
//Plays a G#2 which is mapped to cowbell on the drums of GarageBand | |
#include <MIDI.h> | |
#include <midi_Defs.h> | |
#include <midi_Message.h> | |
#include <midi_Namespace.h> | |
#include <midi_Settings.h> | |
const int pushButton = 53; | |
//Defining the BaudRate used by Hairless MIDI bridge | |
//To use with Arduino default USB 'modem' mode | |
struct MySettings : midi::DefaultSettings | |
{ | |
static const long BaudRate = 115200; | |
}; | |
//midi::MidiInterface<HardwareSerial,midi::DefaultSettings> myMidi(Serial); | |
//midi::MidiInterface<Type> Name((Type&)SerialPort) | |
//MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI); | |
//MIDI_CREATE_DEFAULT_INSTANCE(); | |
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, MySettings); | |
void setup() { | |
//Set the button pin, using internal pullup resistor | |
pinMode(pushButton, INPUT_PULLUP); | |
MIDI.begin(); | |
} | |
void loop() { | |
if (!digitalRead(pushButton) ) { | |
//Button clicked | |
MIDI.sendNoteOn(56,120,1); | |
while(!digitalRead(pushButton)) { | |
//Button is being held | |
} | |
//Button released | |
MIDI.sendNoteOff(56,0,1); | |
} | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment