Pages: [1]   Go Down
Author Topic: Arduino only acting on first instance of receiving midi note#  (Read 816 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I'm trying to send triggers to an analog rhythm machine when arduino receives certain midi note numbers. So far I have been successful with the code below; however, each key I press on my midi controller will trigger the sound on the rhythm machine only once! If I press another key and then the desired key, it will trigger again, but I can't trigger the same sound from the same key multiple times in a row. What am I doing wrong!?!?

Thanks!
Andy

Code:
#include <MIDI.h> // Add Midi Library

#define BASS 2   // Bass Drum triggered from Arduino Pin 2
#define LCONGA 3 // Low Conga triggered from Arduino Pin 3
#define HCONGA 4 // High Conga triggered from Arduino Pin 4
#define HBONGO 5 // High Bongo triggered from Arduino Pin 5
#define CLAVES 6 // Claves triggered from Arduino Pin 6
#define SNARE 7  // Snare Drum triggered from Arduino Pin 7
#define CYMBAL 8 // Cymbal triggered from Arduino Pin 8

void HandleNoteOn(byte channel, byte pitch, byte velocity){
  digitalWrite(BASS, HIGH);
  digitalWrite(LCONGA, HIGH);
  digitalWrite(HCONGA, HIGH);
  digitalWrite(HBONGO, HIGH);
  digitalWrite(CLAVES, HIGH);
  digitalWrite(SNARE, HIGH); 
  digitalWrite(CYMBAL, HIGH);
  if (pitch == 36) {
    digitalWrite(BASS, LOW);
  }
  if (pitch == 64) {
    digitalWrite(LCONGA, LOW);
  }
  if (pitch == 63) {
    digitalWrite(HCONGA, LOW);
  }
  if (pitch == 60) {
    digitalWrite(HBONGO, LOW);
  }
  if (pitch == 75) {
    digitalWrite(CLAVES, LOW);
  }
  if (pitch == 40) {
    digitalWrite(SNARE, LOW);
  }
  if (pitch == 42) {
    digitalWrite(CYMBAL, LOW);
  }
}

void setup(){
  MIDI.begin(MIDI_CHANNEL_OMNI);
  MIDI.setHandleNoteOn(HandleNoteOn);
  pinMode(BASS, OUTPUT);
  pinMode(LCONGA, OUTPUT);
  pinMode(HCONGA, OUTPUT);
  pinMode(HBONGO, OUTPUT);
  pinMode(CLAVES, OUTPUT);
  pinMode(SNARE, OUTPUT);
  pinMode(CYMBAL, OUTPUT);
}

void loop(){
  MIDI.read();
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Figured it out! I had to switch the state of the pins back to HIGH within each IF statement in order to get each key to trigger to sounds of the rhythm machine multiple times in a row. The rhythm machine I've now retrofitted with is the Rhythm Ace FR2L, by the way. I'm currently writing up the documentation for the project on my blog, and will post a link here once the post it up.

Here's the working code:


Code:
#include <MIDI.h> // Add Midi Library

#define BASS 2   // Bass Drum triggered from Arduino Pin 2
#define LCONGA 3 // Low Conga triggered from Arduino Pin 3
#define HCONGA 4 // High Conga triggered from Arduino Pin 4
#define HBONGO 5 // High Bongo triggered from Arduino Pin 5
#define CLAVES 6 // Claves triggered from Arduino Pin 6
#define SNARE 7  // Snare Drum triggered from Arduino Pin 7
#define CYMBAL 8 // Cymbal triggered from Arduino Pin 8

int TIME = 5;

void HandleNoteOn(byte channel, byte pitch, byte velocity){
  digitalWrite(BASS, HIGH);
  digitalWrite(LCONGA, HIGH);
  digitalWrite(HCONGA, HIGH);
  digitalWrite(HBONGO, HIGH);
  digitalWrite(CLAVES, HIGH);
  digitalWrite(SNARE, HIGH); 
  digitalWrite(CYMBAL, HIGH);
  if (pitch == 36) {
    digitalWrite(BASS, LOW);
    delay(TIME);
    digitalWrite(BASS, HIGH);
  }
  if (pitch == 64) {
    digitalWrite(LCONGA, LOW);
    delay(TIME);
    digitalWrite(LCONGA, HIGH);
  }
  if (pitch == 63) {
    digitalWrite(HCONGA, LOW);
    delay(TIME);
    digitalWrite(HCONGA, HIGH);
  }
  if (pitch == 60) {
    digitalWrite(HBONGO, LOW);
    delay(TIME);
    digitalWrite(HBONGO, HIGH);
  }
  if (pitch == 75) {
    digitalWrite(CLAVES, LOW);
    delay(TIME);
    digitalWrite(CLAVES, HIGH);
  }
  if (pitch == 40) {
    digitalWrite(SNARE, LOW);
    delay(TIME);
    digitalWrite(SNARE, HIGH);
  }
  if (pitch == 42) {
    digitalWrite(CYMBAL, LOW);
    delay(TIME);
    digitalWrite(CYMBAL, HIGH);
  }
}

void setup(){
  pinMode(BASS, OUTPUT);
  pinMode(LCONGA, OUTPUT);
  pinMode(HCONGA, OUTPUT);
  pinMode(HBONGO, OUTPUT);
  pinMode(CLAVES, OUTPUT);
  pinMode(SNARE, OUTPUT);
  pinMode(CYMBAL, OUTPUT);
  MIDI.begin(MIDI_CHANNEL_OMNI);
  MIDI.setHandleNoteOn(HandleNoteOn);
}

void loop(){
  MIDI.read();
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's the write-up for the project, for posterity.

http://youthvulture.blogspot.com/2014/03/rhythm-ace-fr-2l-midi-retrofit-with.html
Logged

Pages: [1]   Go Up
Jump to: