Hi Pieter have tried your sendmidi function in my code and its not working
//#include <SPI.h>
#include <usbh_midi.h>
USB Usb;
USBH_MIDI Midi(&Usb);
int tuner = 6;
const uint8_t CC = 0xB0;
int switchPin[5] = {2,3,4,5,14};
int ledPin[5]={7,8,9,13,11};
int currentPreset =0;
int maxPresetNumber = 50; // for Zoom MS70cdr change by this = 50
bool pinState[5];
//int progChange[4] = {+1,-1,+10,-10};
/***********************************************************************************/
void setup()
{
Serial.begin(115200);
for(int i=0; i<5; i++)
{
pinMode(ledPin[i], OUTPUT);
pinMode(switchPin[i], INPUT_PULLUP);
pinMode(tuner,INPUT_PULLUP);
}
if (Usb.Init() == -1)
{
digitalWrite(ledPin[5], HIGH);
while(1); // Halt
}
currentPreset = 0;
//SendMIDI(currentPreset);
}
/***********************************************************************************/
void SendMIDI(byte programChange)
{
Usb.Task();
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
byte Message[2]; // Construct the midi message (2 bytes)
Message[0]=192; // 0xC0 is for Program Change
Message[1]=programChange; // Number is the program/patch
Midi.SendData(Message); // Send the message
delay(10);
}
}
/***********************************************************************************/
void ledsOff()
{
for(int i=0; i<5; i++)
{
digitalWrite(ledPin[i], LOW);
}
}
/***********************************************************************************/
/*void loop() //+1 -1 +10 -10 presets mode
{
for(int i=0; i<4; i++)
{
pinState[i]=digitalRead(switchPin[i]);
if(pinState[i] != HIGH)
{
//currentPreset = programChange[i];
ledsOff();
SendMIDI(programChange[i]);
digitalWrite(ledPin[i], HIGH);
delay(500);
}
else
{
NULL;
}
}
/* if(currentPreset > maxPresetNumber)
{
currentPreset = 0;
}
if(currentPreset < 0)
{
currentPreset = maxPresetNumber;
}
}
***********************************************************************************/
//void loop() //for Zoom MS70cdr
void loop() //4 presets mode
{
for(int i=0; i<4; i++)
{
pinState[i]=digitalRead(switchPin[i]);
if(pinState[i] != HIGH)
{
//Serial.print(pinState[i] ,BIN);
SendMIDI(i); //presets from 1 to 4
ledsOff();
digitalWrite(ledPin[i], HIGH);
delay(200);
}
else
{
NULL;
}
}
int tunstate;
tunstate = digitalRead(tuner); //Switchstate for the tuner.
if(tunstate = HIGH){
sendUSBMIDI(0xB0,1,74,0);
delay(100);
}
else
{
sendUSBMIDI(0xB0,1, 74 ,127);
}
}
void sendUSBMIDI(uint8_t m, uint8_t c, uint8_t d1, uint8_t d2) { // send a 3-byte MIDI event over USB
c--; // Channels are zero-based
m &= 0xF0;
c &= 0xF;
d1 &= 0x7F;
d2 &= 0x7F;
#if defined(CORE_TEENSY) //only include these lines when compiling for a Teensy board
usb_midi_write_packed((m >> 4) | ((m | c) << 8) | (d1 << 16) | (d2 << 24));
#elif defined(USBCON) //only include these lines when compiling for an Arduino if you're compiling for an Arduino that has USB connection in the main MCU but is not a Teensy
midiEventPacket_t msg = {m >> 4, m | c, d1, d2};
MidiUSB.sendMIDI(msg);
MidiUSB.flush();
#else // If you're compiling for an Arduino that has no USB connection in the main MCU
Serial.write(m | c); // Send the MIDI message over Serial.
Serial.write(d1);
Serial.write(d2);
#endif
}
Here it is looking for 4 characters to compile this is what i have (controlchange,midi channel,control change number,data amount)sendUSBMIDI(0xB0,1, 74 ,127);
where am i going wrong.
any help would be great.