Hi folks,
I have been getting alot of help here. I really appreciate it. I have an LED that needs to respond differently to four different pieces of midi velocity information. I'm brand new to programming, so trying to work this out with if else commands. I can't get the LED to blink...If you can, please take a look and tell me what I'm doing wrong! Thank you!
I do have a basic question, in an "if else" statement if I do an "if" and it is false, does it jump straight to the else, or does it just go to the next "if" if there are a string of "if"s before the "else"?
For example, in my code below, if the incoming byte is not 144, how do I get the LED to turn off if it is already on?
void loop () {
if (Serial.available() > 3) { //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==127){ //if velocity is 127 then clip is playing and LED is on
}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){ //if velocity is 126 then clip is launched but not yet playing LED is blinking...but how???
lc.setLed(0,3,3,true); //this is probably wrong?
delay(1000); //this is probably wrong?
}else{ //clip is stopped and LED is off
lc.setLed(0,3,3,false);
}
}
}
}
}
I took the liberty of reformatting your code so it is easier (for me and maybe to you) to follow. I made no changes except at the end where I clearly indicated my addition. Also I added come comments just to clarify what was what. Comments are always a good idea especially where you have a group of brackets together and it might be fuzzy which goes with what.
void loop ()
{
if (Serial.available() > 3)
{ //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==127)
{ //if velocity is 127 then clip is playing and LED is on
}
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)
{ //if velocity is 126 then clip is launched but not yet playing LED is blinking...but how???
lc.setLed(0,3,3,true); //this is probably wrong?
delay(1000); //this is probably wrong?
}
else
{ //clip is stopped and LED is off
lc.setLed(0,3,3,false);
}
} //end of if (incomingByte==60)
} //end of if (incomingByte==144)
// begin added code
else
{
// add whatever you want to do if incomingByte is NOT equal to 144 here
}
// end added code
} //end of if (Serial.available() > 3)
} //end of loop()
if(incomingByte==127)
{ //if velocity is 127 then clip is playing and LED is on
}
else
if(incomingByte==1)
{ //if velocity is 1 then clip is looping and LED is still on
lc.setLed(0,3,3,true);
}
Should I have:
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);
}
Does that matter?
Any advice on how to get this LED to blink:
if(incomingByte==126)
{ //if velocity is 126 then clip is launched but not yet playing LED is blinking...but how???
lc.setLed(0,3,3,true); //this is probably wrong?
delay(1000); //this is probably wrong?
}