Hello,
I'm a beginner in arduino's world. I'm a student who works in electronics, and i have already done some things on mbed (like arduino), or some projects in C.
I discovered arduino at the same time i get my mbed. So i ordered a arduino uno because it has a biggest communauty than mbed.
My project is : i would like to connect a simple hc sr04 to the arduino thanks to a breadboard and then i would like to play notes in MIDI depending on the distance of an object. For example, if my hand is at 30centimeters, it will play a C.
I looked for a software called LoopBe, which simulate a midi output with the usb. Then, i have tried to make a simple program but i dont know if it will work, i will receive my arduino uno tomorrow or the day after tomorrow.
My program is :
int trig = 12; //broche
int echo = 11;
long lecture_echo;
long cm;
void setup()
{
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
pinMode(echo, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
lecture_echo = pulseIn(echo, HIGH);
cm = lecture_echo / 58 //distance in cmeters
if(cm<=70 && cm>60)
{
MIDI_TX(129,60, 127) //play a C
delay(100);
}
else if(cm<=60 && cm>50)
{
MIDI_TX(129,62, 127) //play a D
delay(100);
}
void MIDI_TX(unsigned char MESSAGE, unsigned char DONNEE1, unsigned char DONNEE2) //fonction d'envoi du message MIDI
{
Serial.write(MESSAGE); //envoi de l'octet de message sur le port série
Serial.write(DONNEE1); //envoi de l'octet de donnée 1 sur le port série
Serial.write(DONNEE2); //envoi de l'octet de donnée 2 sur le port série
}
In the function MIDI_TX, 60 and 62 have been taken here : http://newt.phys.unsw.edu.au/jw/graphics/notes.GIF
But it seems wired that it is just like that, i guess i should write something after the function MIDI_TX (i have taken it from a website) but i don't know what... Can someone help me? Thanks in advance