I have a sketch where I am lighting 4 banks of 8 LEDs. If I light an LED in one bank, and then an LED in a second band, both LEDs will stay lit. However when I then light another LED in the first bank, I need to be able to scan through those 8 pins of the first bank and if there are any LEDs lit (only in that bank) then they will be set low before lighting the new LED...
Clear as mud?
I'm using four 595 shift registers to do this, and here is the loop that I'm using:
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(57600);
Serial.println("reset");
}
void loop() {
if (Serial.available()>=3) {
// now at least 3 bytes are in the buffer.
midiMessage = Serial.read() ;
noteNumber = Serial.read() ;
velocity = Serial.read() ;
int pinNumber = noteNumber - 60; //Set The output pin to the MIDI note number - 60.
if (midiMessage == 144){
if (velocity == Triggered){
registerWrite(pinNumber, HIGH);
i = pinNumber;
}
if (velocity == Playing){
registerWrite(pinNumber, HIGH);
}
if (velocity == Looping){
registerWrite(pinNumber, HIGH);
delay(100);
registerWrite(pinNumber, LOW);
delay(100);
registerWrite(pinNumber, HIGH);
}
}
if (midiMessage == 128){
if((i / 8) == (pinNumber / 8)){
registerWrite(pinNumber, LOW);
}
}
}
}
So when an LED is first triggered, it will go in the "triggered" conditional. I'm guessing I need a function call there to check if any other LEDs are lit in the same bank and turn them off if so...
Can anyone show me how to do that? Thanks so much!