Pages: [1]   Go Down
Author Topic: LDR to Arduino to MIDI, URGENT!  (Read 543 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, we're new to the forum, sorry our first post is under such urgent circumstances!
We're trying to use photo-resistors to trigger midi notes however we've stumbled upon a few problems.

Ideally we need the LDR (photo-resistor) circuit to act more like a switch (simply triggering note-on values) rather than churning out continuous controller messages.  
Having set up the LDR to divide the voltage between the +5v pin and ground (giving a continuous input value at analog pin 0), we want to create a statement which essentially says:
When the value at analog-0 goes above a set threshold, we want to trigger  a single note on message.
We have studied every similar Arduino sketch we could find, however nothing seems to quite work out right for us.
We're getting very little in the way of note-on messages, lots of changes in midi channel, nothing consistent. basically... it's a complete mess.
We can be relatively flexible in terms of what the messages being transmitted are, as long as we get 2 clearly defined messages (which we can later transform into what we need in logic).


Internet findings that come 'closest' to success.

Circuit in use:
http://itp.nyu.edu/physcomp/Labs/MIDIOutput

Arduino code in use:
// by Tubedogg 12/2006; fabian at tubedogg.de


http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1165833586

//This program reads up to 6 analog sensors / potentiometers ans converts the data to Midi-Controller messages
// define Switchpin:
#define switchPin 10
//  define LED:
#define LEDpin 13

// Variables

// define variables for the controller data
int AnalogValue[6] = {0,0,0,0,0,0};    

// define the "lastValue" variables
int lastAnalogValue[6] = {0,0,0,0,0,0};

// select the midi Controller Number for each input
int midiCCselect[6] = {1,2,3,4,5,6};

// select threshold for each analog input  
int thresh[6] = {1,1,1,1,1,1};  

// select number of desired analog inputs (max 6)
int input_no = 6;

void setup() {
//  set the states of the I/O pins:
pinMode(switchPin, INPUT);
pinMode(LEDpin, OUTPUT);
//  Set MIDI baud rate:
Serial.begin(31250);

}

// main program loop
void loop() {

for(int i=0;i<input_no;i++){

        AnalogValue = (analogRead(i))/8;    // read the value from the analog input and divide by 8 for range 0-127
    // check if value is greater than defined threshold (good for resistive touchpads etc)
    if ( AnalogValue >thresh ) {
          // check if analog input has changed
          if ( AnalogValue != lastAnalogValue ) {

          //send control change on cc#i
          midiCC(0xB0, midiCCselect, AnalogValue);
          // update lastAnalogValue variable
          lastAnalogValue = AnalogValue;

          //End if
          }
      //End if
    }
 

//End for
}


//End Loop
}



// This function sends a Midi CC.
void midiCC(char CC_data, char c_num, char c_val){
Serial.print(CC_data, BYTE);
Serial.print(c_num, BYTE);
Serial.print(c_val, BYTE);

}

We realise this code is for continuous controllers, however we're pretty sure it should be a simple case of setting up a threshold which splits the continuous data into an on/off message (of some kind, doesnt really matter if it's note data)

Apologies again for the urgency of this post, we're trying to get a piece complete for exhibition very soon and we cant seem to get past this point!
Any 'light' you can shed on your LDR problems would be greatly appreciated.

All the best,
HalGG Cry
Logged

Los Angeles
Offline Offline
Newbie
*
Karma: 0
Posts: 23
what is the what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am also building an LDR-based midi controller.

Mine uses one LDR to determine pitch based on the amount of light falling on the LDR, and a button that sends note on/note off messages.

It sounds like your project involves several LDRs, each of which triggers a distinct midi note when a threshold has passed.

If this is correct, try checking out any midi arduino project that uses FSRs, or any other analog input.

This beatsneaks project helped me out a lot -- try recreating this but replace the FSRs  with LDRs.

http://www.hobgobeclectronics.com/blorg/projects/beatsneaks-i

The thing I am struggling with is forcing my LDR to calibrate to different environments. Mine works great in the dark, but is really iffy in a bright room.

Good luck!
« Last Edit: June 23, 2010, 06:28:41 pm by thedude1977 » Logged

Bremen
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your threshold is 1 - that seems low to me. What's the range of valued you get from the LDR? (the rest of the code seems fine to me)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33371
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a cross post.
Main discussion here:-
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1277264781
Logged

Pages: [1]   Go Up
Jump to: