Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
84 lines (74 sloc) 1.79 KB
#include <Servo.h>
//GLOBAL
int chan = 1;
int ledPin = 13; //MIDI SIGNAL RECOGNIZED INDICATOR
/////4 SERVOS
Servo myServo1;
Servo myServo2;
Servo myServo3;
Servo myServo4;
int pwmVal20;
int pwmVal21;
int pwmVal22;
int pwmVal23;
int ccVal20;
int ccVal21;
int ccVal22;
int ccVal23;
int servoRangeBottom = 0;
int servoRangeTop = 180;
#define SERVOPIN1 3 // CC 20
#define SERVOPIN2 4 // CC 21
#define SERVOPIN3 22 // CC 22
#define SERVOPIN4 23 // CC 23
void myControlChange(byte channel, byte control, byte value) // when "myControlChange" is called, flash the led and store the control change numbers into a variable
{
midiLedFlash();
switch (control)
{
case 20: // for ccSERVO20
ccVal20 = value;
break;
case 21: // for ccSERVO21
ccVal21 = value;
break;
case 22: // for ccSERVO22
ccVal22 = value;
break;
case 23: // for ccSERVO23
ccVal23 = value;
break;
}
}
void midiLedFlash()
{
digitalWrite(ledPin, HIGH);
delay(1);
digitalWrite(ledPin, LOW);
}
void setup()
{
///SERVOS
myServo1.attach(SERVOPIN1);
myServo2.attach(SERVOPIN2);
myServo3.attach(SERVOPIN3);
myServo4.attach(SERVOPIN4);
usbMIDI.setHandleControlChange(myControlChange); // Call usbMIDI callback function, "myControlChange"
pinMode(ledPin, OUTPUT); // midi output led
}
void loop()
{
usbMIDI.read(chan); // read and set channel number
///SERVOS
pwmVal20 = map(ccVal20, 0, 127, servoRangeBottom, servoRangeTop); // adjust range from midi cc (0-127) to (servoRangeBottom to servoRangeTop)
myServo1.write(pwmVal20);
////
pwmVal21 = map(ccVal21, 0, 127, servoRangeBottom, servoRangeTop);
myServo2.write(pwmVal21);
////
pwmVal22 = map(ccVal22, 0, 127, servoRangeBottom, servoRangeTop);
myServo3.write(pwmVal22);
////
pwmVal23 = map(ccVal23, 0, 127, servoRangeBottom, servoRangeTop);
myServo4.write(pwmVal23);
}