PieterP:
The Control Surface library I'm working on should support this.
Here's an example that reads MIDI note inputs and turns on / off LEDs connected to 74HC595 shift registers: https://tttapa.github.io/Control-Surface/Doc/Doxygen/dd/dcc/md_Getting-Started.html#first-input
Pieter
Thanks for your advice, I tried it out but it didn't compile so I'm going further with my own code that I'm a bit curious about. Any idéas how to get this puzzle together?
First of all, do my shiftOut look ok? Second of all, how do I get my shiftOut to talk to my other two functions? Feeling kind of stupid...
Variables
//SHIFT REGISTER FOR LEDS, OUTPUT PINS_____________________
int latchPin = 10; // ST_CP, SS (Storage register clock pin)
int clockPin = 14; // SH_CP, SCK (Shift register clock pin) Set to alternative pin 14, since internal led using 13!
int dataPin = 11; // DS, MOSI (data out from Teensy, into 595)
Setup
//USB MIDI_____________________
usbMIDI.setHandleNoteOff(OnNoteOff);
usbMIDI.setHandleNoteOn(OnNoteOn);
digitalWrite (latchPin, HIGH);
delay(400);
digitalWrite(latchPin, LOW);
//SHIFT REGISTER FOR LEDS, OUTPUT PINS_____________________
//set shift register pins to output
pinMode(latchPin, OUTPUT);
Loop
usbMIDI.read();
Functions
void OnNoteOn(byte channel, byte note, byte velocity) {
digitalWrite(latchPin, HIGH); // Any Note-On turns on LED
}
void OnNoteOff(byte channel, byte note, byte velocity) {
digitalWrite(latchPin, LOW); // Any Note-Off turns off LED
}
void shiftOut(int dataPin, int clockPin, byte note) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(dataPin, 0);
digitalWrite(clockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(clockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( note & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(dataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(clockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(dataPin, 0);
}
//stop shifting
digitalWrite(clockPin, 0);
}