I would like to make a very simple king of midi Theremin, with a HC SR04 module to pitch the notes.
But first thing first, i'm starting by sending a simple note from Arduino Uno to my midi software.
I did the simpliest thing possible (official Arduino example) :
It's plugged to a midi/usb interface which is talking to my midi software (ableton live), and i can hear a midi simple note with the code below.
Great !
My next step is to pitch bending this note, and ... i haven't found the working message !
I read lot's of thing about sending midi message, but i haven't found a simple example that working with my arduino uno ...
Help my ears
/*
So simple midi
*/
int speed_com = 31250; // the midi speed
int note;
void setup(){
Serial.begin(speed_com); // init serial speed
playMidi (0x90, 0x5A, 0x45); // play on channel 1, never ending pain of my ears !
}
void loop(){
delay (2000);
// NOW, PITCH ME, PLEASE !!!
}
void playMidi (int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
Pitch Wheel Change. 0mmmmmmm This message is sent to indicate a change in the pitch wheel. The pitch wheel is measured by a fourteen bit value. Center (no pitch change) is 2000H. Sensitivity is a function of the transmitter. (llllll) are the least significant 7 bits. (mmmmmm) are the most significant 7 bits.
Pitch Wheel Change message:
// Value is +/- 8192
void PitchWheelChange(int value) {
unsigned int change = 0x2000 + value; // 0x2000 == No Change
unsigned char low = change & 0x7F; // Low 7 bits
unsigned char high = (change >> 7) & 0x7F; // High 7 bits
playMidi(0xE0, low, high);
}
Okayyyyyyy, i think i have something now.
Hearing the cops coming with a loop
/*
So simple midi
*/
int speed_com = 31250; // the midi speed
int note;
void setup(){
Serial.begin(speed_com); // init serial speed
playMidi (0x90, 0x5A, 0x45); // play on channel 1, never ending pain of my ears !
}
void loop(){
// NOW, PITCH ME, PLEASE !!!
for (int i=2000 ; i < 8000 ; i+=5){
// you're under arrest, cops are singing !
PitchWheelChange(i);
}
}
void playMidi (int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}
// johnwasser was here !
// Value is +/- 8192
void PitchWheelChange(int value) {
unsigned int change = 0x2000 + value; // 0x2000 == No Change
unsigned char low = change & 0x7F; // Low 7 bits
unsigned char high = (change >> 7) & 0x7F; // High 7 bits
playMidi(0xE0, low, high);
}
I'm not sure where i'm going with that, but i'm learning !
I think i'm gonna try adding a potentiomer to drive your function.
If someone looking for me, i'm in the lab !
I was about to use the map command on my own (yeah i swear !) to constrain the numbers between 0 and 1023...
Your way is much more elegant on a single line.
Great again !
Time to use the Ultrasonic Sensor !!!