Are you saying to use a switch statement? That's what I'm reading about now...
The switch statement can be usefull but I wrote about this : millis() - Arduino Reference
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 :-/
Here's what I have so far
//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
I would do it that way. You have to adapt it for more leds !
//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 ;))