USBmidi.read to 595 shift registers via SPI

Status
Not open for further replies.

Imbecillen

New member
Hello,

I can't grasp how I should implement a USBmidi callback array to store my bits/bytes and compare these with previous states into my code. Any advice would help a lot!

I use 16 buttons to send midi to my computer, then I receive midi callback that's supposed to light up 16 corresponding leds. This is made with two daisy chained 595 shift registers via SPI.

Since I've been vacuuming the whole internet for similar projects and can't find any answers I go for it here and hope for some help!

The hardware works great if I send 0xFF messages in the function voids. Here's some of my code of what I think is relevant, not complete and probably not right:


Setup:
Code:
  //SHIFT REGISTER PIN________________________________
  uint8_t const latchPin = 8; // ST_CP, SS (STorage Clock Pin, Slave Select)


  //SPI SETTINGS________________________________
  SPI.setMOSI(11);  // DS, MOSI (data out from Teensy, into 595)
  SPI.setSCK(14);   // SH_CP, SCK (Shift register clock pin) Set to alternative pin 14, instead of 13 which TEENSY LED uses
  SPI.begin();  

  //SHIFT REGISTER OUTPUT_______________________
  pinMode(latchPin, OUTPUT);

  //USB MIDI NOTE HANDLES_____________________
  usbMIDI.setHandleNoteOff(OnNoteOff);
  usbMIDI.setHandleNoteOn(OnNoteOn);


Loop:
Code:
void loop() {
usbMIDI.read();
}


Functions:
Code:
// NOTE ON, SHIFT OUT TO LED________________________________________
void OnNoteOn(byte channel, byte note, byte velocity) {
  digitalWrite(latchPin, LOW);
  SPI.beginTransaction( SPISettings(48000000, MSBFIRST, SPI_MODE0 ) );
  SPI.transfer (note);
  SPI.transfer (velocity);
  SPI.endTransaction();
  digitalWrite (latchPin, HIGH);
  delayMicroseconds (50);
}


// NOTE OFF, SHIFT OUT TO LED________________________________________ 
void OnNoteOff(byte channel, byte note, byte velocity) {
  digitalWrite(latchPin, LOW);
  SPI.beginTransaction( SPISettings(48000000, MSBFIRST, SPI_MODE0 ) );
  SPI.transfer (note);
  SPI.transfer (velocity);
  SPI.endTransaction();
  digitalWrite (latchPin, HIGH);
  delayMicroseconds (50);
}
 
Status
Not open for further replies.
Back
Top