dear folks,
sorry for sparing any decent code-example - i'm at the very beginning of learning and can't wrap my mind around this issue being so difficult
i'm (simply?) trying to set any of 11 digital pins HIGH for a very short period of time (~40ms) when a NoteOn is received via midi. i've got the midi-part running, and actually a version that partially works for NoteOns and NoteOffs, how ever this appears of no use in the given scenario..
can anybody help or point me towards the right direction? i've found various examples on setting (up to 2) pins HIGH via millis() in a given interval, how ever nothing that's event-based.
i'd be gracious!
//variables setup
byte incomingByte;
byte note;
byte velocity;
int c = 2;
int d = 3;
int e = 4;
int f = 5;
int g = 6;
int a = 7;
int h = 8;
int c2 = 9;
int d2 = 10;
int e2 = 11;
int f2 = 11;
//0 =note off ; 1=note on ; 2= nada
int action=2;
//setup: declaring iputs and outputs and begin serial
void setup() {
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
//start serial with midi baudrate 31250 or 38400 for debugging
Serial.begin(31250);
}
//loop: wait for serial data, and interpret the message
void loop () {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// wait for as status-byte, channel 16, note on or off
if (incomingByte== 159){ // note on message starting starting
action=1;
}else if (incomingByte== 143){ // note off message starting
action=0;
}else if ( (action==0)&&(note==0) ){ // if we received a "note off", we wait for which note (databyte)
note=incomingByte;
playNote(note, 0);
note=0;
velocity=0;
action=2;
}else if ( (action==1)&&(note==0) ){ // if we received a "note on", we wait for the note (databyte)
note=incomingByte;
}else if ( (action==1)&&(note!=0) ){ // ...and then the velocity
velocity=incomingByte;
playNote(note, velocity);
note=0;
velocity=0;
action=0;
}else{
//nada
}
}
}
void playNote(byte note, byte velocity){
int value=LOW;
if (velocity >0){
value=HIGH;
}else{
value=LOW;
}
//since we don't want to "play" all notes we wait for a note between 36 & 44
if(note==36){
digitalWrite(c, value);
}
else if (note==38){
digitalWrite(d, value);
}
else if (note==39){
digitalWrite(e, value);
}
else if (note==40){
digitalWrite(f, value);
}
else if (note==41){
digitalWrite(g, value);
}
else if (note==42{
digitalWrite(a, value);
}
else if (note==43{
digitalWrite(h, value);
}
else if (note==44{
digitalWrite(c2, value);
}
else if (note==45{
digitalWrite(d2, value);
}
else if (note==46{
digitalWrite(e2, value);
}
else if (note==47{
digitalWrite(f2, value);
}
}