Pages: [1]   Go Down
Author Topic: Make Arduino Uno read MIDI timing clock signal and turn on a LED  (Read 847 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.
It is my first time on the Arduino forum.
I need some help please.
Just so you know, english is not my first language, I'll do my best.

Here's my situation :
I have an Arduino Uno v3.
I'm a musician and I work with a Korg Electribe drum machine which sends midi timing clock signal thru it's MIDI out.
I play with a drummer/percussionist and would like him to see midi timing clock signal outputted by the drum machine.
I thought of using a LED plugged in pin 13 of the Arduino.
I made the connection with a MIDI cable on the Arduino as explained in the MIDI tutorial.
I did some research over the web to find some ideas for the code.
Here's the code I'm using right now but it does not work :

Code:
byte midi_start = 0xfa;
byte midi_stop = 0xfc;
byte midi_clock = 0xf8;
byte midi_continue = 0xfb;
int play_flag = 0;
byte data;

void setup() {
  Serial.begin(31250);
}

void loop() {
  if(Serial.available() > 0) {
    data = Serial.read();
    if(data == midi_start) {
      play_flag = 1;
    }
    else if(data == midi_continue) {
      play_flag = 1;
    }
    else if(data == midi_stop) {
      play_flag = 0;
    }
    else if((data == midi_clock) && (play_flag == 1)) {
      Sync();
    }
  }
}

void Sync() {
  digitalWrite(13, HIGH);
  delay(10);
  digitalWrite(13, LOW);
  delay(10);
}

------------------------------------------
Would you have any idea what is wrong with my code?
Thank very much for your help.

Moderator edit: [code] ... [/code] tags added. (Nick Gammon)
« Last Edit: October 23, 2013, 11:39:58 pm by Nick Gammon » Logged

Argentina
Offline Offline
Full Member
***
Karma: 5
Posts: 147
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That code is from little-scale if i remember well, and it does work.
 What's happening? The LED doesn't work?
First you need to make the pin 13 an output. Without pinMode(13, OUTPUT); it's acting like an input. Digitals are input by default.

Second, is the MIDI communication working? Are the RX/TX leds flashing?

Thirrrd, your Electribe is sending standard MIDI clock i suppose. What do you want to do with that data? Make the LED go on and off? How often? MIDI clock sends 24 pulses per 1/4 note. If you have a BPM of 120, you have a 1/4 note of 500ms, and each MIDI clock pulse is 20.833ms. So you're calling Sync(); at a rate of 20ms, I doubt your drummer will see that ahah. Even with the 10ms delay, if your MIDI connection is working ok, and the LED is ok(declared pin 13 as output) you'll surely see it always ON.

 You need to make a counter. Say, you want your LED to blink each 1/4 note, or 1/8? or 1/16?
 Declare a variable that increases each time Sync() is called, and once it reached 24(the last MIDI clock pulse of the 1/4 note) reset the counter to 0 and make the LED go on, else, LED off. Maybe the blink will be to fast, the LED will be on for only a MIDI clock pulse. So instead of the else LED go off, you can wait let's say 4 pulses, and then LED off.
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19351
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What capicoso about making the pin output.

Plus, I agree that the MIDI timing clock may not prove much. Do you want something else, like the drum beat? That could be quite different from the MIDI timing signal.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Pages: [1]   Go Up
Jump to: