I'm modifying the ShiftOut Example code to accept MIDI input to change LEDs.
Currently I have the LEDs changing one by one, but I need to have one LED blink while the other is still on.
I have this code:
void loop() {
if (Serial.available()>=3) {
// now at least 3 bytes are in the buffer.
First = Serial.read() ;
Second = Serial.read() ;
Third = Serial.read() ;
int bitToSet = Second - 60; //Set The output pin to the MIDI note number - 60.
if (First == 144){
if (Third == 127){
registerWrite(bitToSet, HIGH);
}
}
}
}
This works well, but when a new MIDI signal comes in, it turns off the previous LED. I need to keep the LED lit until a signal with Third == 0
comes through.
I guess to be more clear, I first need to know how to extend my code to keep one LED lit while the next LED gets lit.
Thanks for any help, and here is my complete code:
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;
int First = 0;
int Second = 0;
int Third = 0;
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.
First = Serial.read() ;
Second = Serial.read() ;
Third = Serial.read() ;
int bitToSet = Second - 60; //Set The output pin to the MIDI note number - 60.
if (First == 144){
if (Third == 127){
registerWrite(bitToSet, HIGH);
registerWrite(bitToSet + 2, HIGH);
}
}
}
}
// This method sends bits to the shift register:
void registerWrite(int whichPin, int whichState) {
// the bits you want to send
byte bitsToSend = 0;
// turn off the output so the pins don't light up
// while you're shifting bits:
digitalWrite(latchPin, LOW);
// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);
// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);
}