Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (44 sloc) 999 Bytes
// USB MIDI receive example, control change to control motor or led pwm
int pwmPin1 = 6;
int pwmPin2 = 9;
int pwmPin3 = 10;
int pwmPin4 = 16;//ignor unless you use a second ULN
int midiLed = 13;
void myControlChange(byte channel, byte control, byte value)
{
midiLedFlash();
switch (control)
{
case 20://cc #
analogWrite(pwmPin1, value * 2);
break;
case 21:
analogWrite(pwmPin2, value * 2);
break;
case 22:
analogWrite(pwmPin3, value * 2);
break;
case 23:
analogWrite(pwmPin4, value * 2);
break;
}
}
void midiLedFlash()
{
digitalWrite(midiLed, HIGH);
delay(1);
digitalWrite(midiLed, LOW);
}
void setup()
{
pinMode(midiLed, OUTPUT);
usbMIDI.setHandleControlChange(myControlChange); // Call usbMIDI callback function, "myControlChange"
digitalWrite(midiLed, HIGH);//so you know that the setup has been initialized
delay(1000);
digitalWrite(midiLed, LOW);
delay(1000);
}
void loop()
{
usbMIDI.read();
}