Go Down

Topic: Can I pay someone to write a sketch for me? (Read 2569 times) previous topic - next topic

mbira

lol.  I'll happily donate to your cause.  Got paypal?  

Thanks for the clear explanation in the code.  I understand much more now.  There still seems to be a problem in the lighting of the LED.  I'm getting the signal out of ableton and into arduino (the RX led is lighting).  Midiox is telling me I'm sending the right information, though it is written in hex on midiox-could that be the problem?


I think most likely, I have just done something stupid and dropped a bit of code somewhere or something.  Thank you for your help and patience in working with me!  Here is the complete code I'm using now:

Code: [Select]
//We always have to include the library
#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;


//variables setup
byte incomingByte;

int statusLed = 13;   // select the pin for the LED



void setup() {
 /*
  The MAX72XX is in power-saving mode on startup,
  we have to do a wakeup call
  */
 lc.shutdown(0,false);
 /* Set the brightness to a medium values */
 lc.setIntensity(0,8);
 /* and clear the display */
 lc.clearDisplay(0);



//setup: declaring iputs and outputs and begin serial

 pinMode(statusLed,OUTPUT);   // declare the LED's pin as output
 Serial.begin(57600);        //start serial with midi baudrate 31250 or 38400 for debugging
}



void loop () {

if (Serial.available() > 0) { //if serial incoming
   incomingByte = Serial.read(); //read it
   if (incomingByte==144){ // analyse the first byte (status) : 144 is note on ch1
     incomingByte = Serial.read(); //read the next byte

     if (incomingByte==60){ // analyse the second byte (note) : 60 is middle C
       incomingByte = Serial.read(); //read the next byte
       if(incomingByte>0){  //analyse the third byte : velocity >0
         lc.setLed(0,3,3,true);
       }else{ //analyse the third byte : velocity=0
         lc.setLed(0,3,3,true);
       }
     }
     if (incomingByte==61){ // analyse the second byte (note) : 61 is middle C#
       incomingByte = Serial.read(); //read the next byte
       if(incomingByte>0){  //analyse the third byte : velocity >0
         lc.setLed(0,3,3,true);
       }else{ //analyse the third byte : velocity=0
         lc.setLed(0,3,3,false);
       }
     }

   }
}

}


Cheers!
Joel Laviolette

mbira

After reading as much as my eyes will allow today and trying lots of different ideas...I'm pretty sure that the problem is somewhere with the assigning of the pins?

A couple areas of the code, I'm unclear on is this:
int statusLed = 13;   // select the pin for the LED

and this:
 pinMode(statusLed,OUTPUT);   // declare the LED's pin as output

What are these supposed to be doing?

Cheers,
Joel


tep

You can remove those, that was for the onboard 13 pin LED.
Did you test the matrix as is with the example code? (for the connection)

mbira

I had a bit of other help and changed
Serial.available() > 0
to
Serial.available() > 3

Now I get the LED to light up.
:D

Now I'm moving on to how to get the LED to respond to the specific velocity signals...

This part here:

a) clip has been triggered but is not yet playing:
message type: NOTE ON
velocity: 126 (LED is BLINKING)

b) clip is playing:
message type: NOTE ON
velocity: 127 (LED is ON)

c) clip is looping:
message type: NOTE ON
velocity: 1 (LED is ON)

d) clip has been stopped:
message type: NOTE OFF
velocity: 0 (LED is OFF)

tep

#19
Sep 01, 2009, 10:16 am Last Edit: Sep 01, 2009, 10:17 am by tep Reason: 1
IMO, for the blinking one you should look into modifying the code in to parts inside the loop:
- The first one listen like now for MIDI IN and puts into variables (one for each led) the status : 0 for off, 1 for on and 2 for blink.
- The second part you check those variables and do it.
 For the blink the trick is that you must do a checkpoint (see millis() in reference and forum) and check each time it arrives at this condition (the main loop is very fastly done!) if millis()>checkpoint+500 and change then the led.
Note also that you need to have a variable for global status of the blinking leds (blinking=1 means for exemple all the blinking ones are on).

I hope this is clear, experiment a little the millis() function to understand how it works!  ;)

mbira

Are you saying to use a switch statement?  That's what I'm reading about now...

tep

The switch statement can be usefull but I wrote about this : http://arduino.cc/en/Reference/Millis

mbira

Ugh,
Going nuts trying to figure out how to make that last LED blink.  I have read the above reference, but I don't understand hot to implement it with the matrix.  Please help!  I have the other three states working correctly (still for this first LED).

I do not understand how to set the blink without Delay using milli since the LED is connected to the max, and not a direct digital pin...

:-[ :o :-/


mbira

Here's what I have so far

Code: [Select]
//We always have to include the library
#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);




//variables setup
byte incomingByte;


unsigned long delaytime = 100;



void setup() {
 /*
  The MAX72XX is in power-saving mode on startup,
  we have to do a wakeup call
  */
 lc.shutdown(0,false);
 /* Set the brightness to a medium values */
 lc.setIntensity(0,8);
 /* and clear the display */
 lc.clearDisplay(0);



//setup: declaring iputs and outputs and begin serial


 Serial.begin(57600);        //start serial with midi baudrate 57600
}




void loop () {

if (Serial.available() > 3) { //if serial incoming
   incomingByte = Serial.read(); //read it

   if (incomingByte==144){} // analyze the first byte (status) : 144 is note on ch1
    else {lc.setLed(0,3,3,false);} //if the first byte is not a note on message, LED is off

   incomingByte = Serial.read(); //read the next byte

     if (incomingByte==60){              // If the byte is note60

       incomingByte = Serial.read();     //read the next byte

       if(incomingByte==127){            //if velocity is 127 then clip is playing and LED is on
       lc.setLed(0,3,3,true);

       }else if(incomingByte==1){        //if velocity is 1 then clip is looping and LED is still on
         lc.setLed(0,3,3,true);

        }else if(incomingByte==126){
        lc.setLed(0,3,3,true);           //if velocity is 126 then clip is launched but not yet playing LED is blinking...but how???
        delay(100);
        lc.setLed(0,3,3,false);
        delay(100);  //this is probably wrong?

        }else{ //The LED will shut off if the above paremeters are not met
         lc.setLed(0,3,3,false);

       } //close else

     }


   } //close first if
} //close loop

tep

#24
Sep 02, 2009, 12:30 pm Last Edit: Sep 02, 2009, 12:31 pm by tep Reason: 1
I would do it that way. You have to adapt it for more leds !

Code: [Select]
//We always have to include the library
#include "LedControl.h"

/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);

/////////NEW variables
int blinkingledsare=0;
int ledstatus[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int ledwas[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int lednumber=1;
unsigned long checkpoint;

//variables setup
byte incomingByte;



void setup() {
 /*
  The MAX72XX is in power-saving mode on startup,
  we have to do a wakeup call
  */
 lc.shutdown(0,false);
 /* Set the brightness to a medium values */
 lc.setIntensity(0,8);
 /* and clear the display */
 lc.clearDisplay(0);



//setup: declaring iputs and outputs and begin serial


 Serial.begin(57600);        //start serial with midi baudrate 57600
}




void loop () {
//listening loop
if (Serial.available() > 3) { //if serial incoming
   incomingByte = Serial.read(); //read it

   if (incomingByte==144){} // analyze the first byte (status) : 144 is note on ch1
    else {lc.setLed(0,3,3,false);} //if the first byte is not a note on message, LED is off

   incomingByte = Serial.read(); //read the next byte

     if (incomingByte==60){              // If the byte is note60

       incomingByte = Serial.read();     //read the next byte

       if(incomingByte==127){            //if velocity is 127 then clip is playing and LED is on
           ledstatus[0]=1; //on
       }else if(incomingByte==1){        //if velocity is 1 then clip is looping and LED is still on
           ledstatus[0]=1; //on
        }else if(incomingByte==126){
            ledstatus[0]=2;  //blink
        }else{ //The LED will shut off if the above paremeters are not met
           ledstatus[0]=0; //off
       } //close else

     }


   } //close first if incoming
   
   
//Let's do it

 if(ledstatus[0]!=ledwas[0]){
  if(ledstatus[0]==1){lc.setLed(0,3,3,true);} //do on
  if(ledstatus[0]==0){lc.setLed(0,3,3,false);}// do off
  if(ledstatus[0]==2 && millis()>(checkpoint+500) ){ //change blink status if half second passed since last time
    if(blinkingledsare==0){ //if blinking leds were off
      lc.setLed(0,3,3,true); //on
      blinkingledsare=1; //change status
      checkpoint=millis(); //checkpoint
    }
    if(blinkingledsare==1 && millis()>(checkpoint+500) ){
      lc.setLed(0,3,3,false);
      blinkingledsare=0;
      checkpoint=millis();
    }
  }
 }
 
//}
   
   
   
   
   
} //close loop


(Btw my e-mail is below, but I was just kidding about the title! Here we prefer to help the people learn step by step than doing it for them ;))

Go Up