Go Down

Topic: LDR with logic pro 9 (midi trigger) (Read 4103 times) previous topic - next topic

Okay I got this to work and the sound from logic is getting to analog pin 0.  But Idk how to get them to work together or which par the original code I was using (not the arduino example) works with the ldr. 


There is no analogRead() anywhere in the code? That seems like a good place to start looking to me.
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

I uploaded the example's code to what I already had.
[codeMidi_touch_2.ino: In function 'void setup()':
Midi_touch_2:129: error: redefinition of 'void setup()'
Midi_touch_2:42: error: 'void setup()' previously defined here
Midi_touch_2.ino: In function 'void loop()':
Midi_touch_2:134: error: redefinition of 'void loop()'
Midi_touch_2:51: error: 'void loop()' previously defined here

If it reads "previously defined here: doesn't it mean it was already there.


If it reads "previously defined here: doesn't it mean it was already there.


You should get a grip of at least the very basics of programming, it is hard to help you when you don't know what the help means.
It is like helping some one to do a hurdles race and finding out they can't stand up yet.

To join two pieces of code you need to do what it tells you here:-

Okay, I hear ya grumpy mike. I shall read your article and learn the basics.
But just for the record this thing is actually working!
The ldr is triggering sounds from  logic. The only problem is it's only working in the dark?!(any thoughts?)
It says also that I need to share the 5v line for the other ldrs. Does that mean I put multiple jumpercables in the same input on arduino?

A recap.
I'm running this code ;

Code: [Select]
unsigned char PadNote[4] = {45,55,60,67};         // MIDI notes from 0 to 127 (Mid C = 60)
                                                  // Imagine a piano roll. 45 55 are keys located on the middle for example.
                                                  // Tweak it to what sounds better to you.

int CutOff = 40;   // This is the minimal amount of analog reading before triggering the note!

int MaxPlayTime[6] = {6500,6500,6500,6500};               // Cycles before a 2nd hit is allowed
                                                          // Best value after lots of trial and error.

#define  midichannel 0;                              // MIDI channel from 0 to 15 (+1 in "real world")

// Internal Use Variables
// You should tweak here if it's not optimal yet.
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Those values work perfectly when using the small LDR and 1K Resistor. So used it!

boolean activePad[6] = {0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[6] = {0,0,0,0};                     // Counter since pad started to play

int ActivePadMinTime = 100;
int PinPauseTimeDelay = 200;
int PinPauseTime[4] = {0,0,0,0};
int PinAvailable[4] = {1,1,1,1};

unsigned char status;

int pin = 0;     
int hitavg = 0;
int maxread = 0;
int debug = false;
int noteOffset = 0;

// Setup

void setup()
  Serial.begin(57600);                                  // connect to the serial port 57600

// Main Program

void loop()
  for(int pin=0; pin <= 3; pin++)
      hitavg = analogRead(pin);    // read the input pin


      if(hitavg < CutOff)   {
        if(debug)Serial.println("hitavg < CutOff");
        if(activePad[pin] == false) {
             if(debug)     Serial.println("activePad[pin] == false");
          if(PinAvailable[pin] == true)
           if(debug) Serial.println("PinAvailable[pin] == true");
            // Toca a nota full
            activePad[pin] = true;
            PinPauseTime[pin] = 0;

            MIDI_TX((0x90 | pin), PadNote[pin]+noteOffset, 127);

         if(debug)   Serial.println("NoteON");

     if(activePad[pin] == true) {
       if(debug)Serial.println("activePad[pin] == true");
       PinPlayTime[pin] += 1;

       if(analogRead(pin) > CutOff && PinPlayTime[pin] > ActivePadMinTime)
               if(debug) Serial.println("analogRead(pin) > PadCut == TRUE");
         activePad[pin] = false;
         PinAvailable[pin] = 2;
         Serial.println("NoteOFF, available is now false. active is false;");

         MIDI_TX((0x80 | pin), PadNote[pin]+noteOffset, 50);
         PinPlayTime[pin] = 0;


     if(PinAvailable[pin] == 2 && PinPauseTime[pin] > PinPauseTimeDelay) {
       if(debug)Serial.println("PinAvailable[pin] == false && PinPauseTime[pin] > 10");
      PinAvailable[pin] = true;
     } else if(PinAvailable[pin] == 2) {
       if(debug)Serial.println("PinPauseTime[pin] += 1;");
       PinPauseTime[pin] += 1;


// Transmit MIDI Message
void MIDI_TX(uint8_t MESSAGE, uint8_t PITCH, uint8_t VELOCITY)
  //status = MESSAGE + midichannel;
  //status = MESSAGE + pin;

And I've wired the breadboard  just like in this picture. -http://cdn.instructables.com/FBA/Y5SV/GJQEIOFT/FBAY5SVGJQEIOFT.MEDIUM.jpg

Download this and fallowed instructions.

And thats it!


It says also that I need to share the 5v line for the other ldrs. Does that mean I put multiple jumpercables in the same input on arduino

I am not sure what you mean by work in the dark.
If you want to reverse the sense in which the light triggers chang all the
Code: [Select]

  ....... = analogRead(
...... = 1023 - analogRead(

Yes, I don't understand it either. The hole breadboard has to be covered or only "dimly lit" for the arduino to be triggered.
For example, I have to have my hand over the breadboard(to shield from light) then totally cover the ldr with me finger for it to trigger the midi.


It is all to do with this line:-
Code: [Select]

int CutOff = 40;   // This is the minimal amount of analog reading before triggering the note!

Try changing the values as a result of what you see being printed out from this line:-
Code: [Select]


Be sure to make this change as well in order for that to print out:-
Code: [Select]

int debug = true;

Okay, so i don't know what happened but the ldr stopped working, the sound is still getting to te arduino but not the ldr.
I didn't even get a chance to try changing tose values or any of the code.
I will post back when the ldr starts working.
I am determined to get this thing working!

Ldr up and running again!
So I will try to get those values straight.
Any ideas how to add more ldrs?  ( only one is working so far and when i try adding more they don't work)


Add more by doing the same thing on a different analog port.
Arduino Libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com


Adding more LDRs requires differant code. The way your code is at the moment is very inefficient , it is not simply a matter of copy and paste you need to use arrays to get it better.

Okay guys. Just for an update, the ldr is still working but only in dim settings (doesnt work at all in the morning). Which I'm cool with so long as I can get 5-6 ldrs working.
Had no luck figuring out how the arrays work or printing values.
Just wanna keep this thread going and see it through so any future  project doers can consider this a sure thing.

Hello. I'm back. Been about 7 months since I tried to finish this project.
Still just have the one ldr working.
I'm thinking the remaining 4, 5 shouldn't be to hard. (stuck in the gamble again!) lol

So I'm looking to ad arrays to the code I've provided above, if anyone can help with that. (I geuss that will be a worthy project for anyone intrested afterwards).

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131