Devices & Components
Arduino Mega 2560 Rev3
Resistor 330 ohm
LED (generic)
Software & Tools
hairlessmidi
loopmidi
Arduino IDE
Project description
Code
sketch_nov08a.ino
arduino
1// arduino mega PWM pins we will use with leds 2int led[10]={2,3,4,5,6,7,8,9,10,11}; 3//cc midi messages three bytes 4byte statusByte; 5byte ControllerNumber; 6byte ControllerValue; 7//cc midi message channel 1 1011 0000 8byte ccmidi = 176; 9 10void setup(){ 11 //test the leds 12 for(int i=0;i<10;i++){ 13 pinMode(led[i],OUTPUT); 14 for(int j=0;j<255;j++){ 15 analogWrite(led[i],j); 16 delay(1); 17 } 18 analogWrite(led[i],0); 19 } 20 //start the serial into the boud rate of 115200 21 Serial.begin(115200); 22} 23void loop(){ 24 //waite for a midi message 25 while(Serial.available() <3); 26 //run the function that will control the leds 27 readmidi(); 28 29 } 30void readmidi(){ 31 32 do{ 33 //sheck if there is any message 34 if (Serial.available()){ 35 //store the data into the variables 36 statusByte = Serial.read(); 37 ControllerNumber = Serial.read(); 38 ControllerValue = Serial.read(); 39 //check if the message is a cc midi message 40 if (statusByte==ccmidi){ 41 42 //controll the leds acording to the data bytes 43 for(int i=0;i<10;i++){ 44 if(ControllerNumber==i+22) analogWrite(led[i],ControllerValue*2); 45 } 46 } 47 } 48 } 49 //repeat until there is no message 50 while (Serial.available() > 2); 51} 52 53
Downloadable files
untitled
untitled
untitled
untitled
Comments
Only logged in users can leave comments