You will need an Arduino library, this one will work and the page behind this link also explains how to install it in your Arduino programming environment.
- Open your Arduino programming environment (IDE).
- In the menu go to Sketch > Include Library > Library Manager...
- Search for a library called Arduino MIDI and install it
Here's the link to the library: Arduino MIDI library
Load this code into your Arduino:
#include <MIDI.h>
const int DEFAULT_MIDI_CHANNEL = 1;
// created and binds the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages
pinMode(A5, INPUT);
}
void loop() {
int reading = analogRead(A5);
Serial.println(reading);
delay(sampleRate);
// midi only supports values from 0 to 127 so we map our reading from
// the full range to the midi range
int midiValue = map(reading, 0, 1024, 0, 127);
// send midi cc message
MIDI.sendControlChange(1, midiValue, DEFAULT_MIDI_CHANNEL);
}
If your Arduino is connected to your LDR sensor circuit it should start pumping MIDI control values back to your computer. To route the MIDI signals from our computer's serial input to our other MIDI-aware software you will need a virtual MIDI connector.
I use Hairless MIDI. It's simple, it's free and does exactly what it says and nothing more.
Open Hairless MIDI, select the serial port where your Arduino is connected as your input and route the MIDI signal to your DAW on the Hairless output.
Hey dude I really like this project, I've had an idea to have a kind of light based MIDI controller/"theremin" for a while.
Slight problem with the code: apparently the "SampleRate" needed to be declared globally (if so, how? I just do "int sampleRate;").
Even when I do this and the code verify's it will still not upload. I'm using an Uno, is the code it meant to be compatible with one?