Advertisement
iampiergiu

arduino midi leds (midiLeds.ino)

Apr 29th, 2012
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /*
  2. midi leds
  3. pier giuliano nioi
  4. http://piergiu.wordpress.com
  5. */
  6. union serial_super_data {
  7.    unsigned long int_4_bytes;
  8.    unsigned char read_byte[4];
  9. } super_data;
  10.  
  11. //setup: declaring inputs and outputs and begin serial
  12. void setup() {
  13.   pinMode(2,OUTPUT);
  14.   pinMode(3,OUTPUT);
  15.   pinMode(4,OUTPUT);
  16.   pinMode(5,OUTPUT);
  17.   pinMode(6,OUTPUT);    
  18.   Serial.begin(57600);    
  19. }
  20.  
  21. //loop: wait for serial data, and interpret the message
  22. void loop () {
  23.    if (Serial.available() >= 3)  // wait for three bytes
  24.     {
  25.       for(int i=0;i <=3; i++)
  26.       super_data.read_byte[i]=Serial.read();
  27.       switch (super_data.read_byte[0]) {
  28.         case 144:// note on message starting starting    
  29.           lightLed(super_data.read_byte[1], HIGH);
  30.           break;
  31.         case 128:// note off message starting      
  32.           lightLed(super_data.read_byte[1], LOW);
  33.           break;
  34.         default:
  35.           break;//nada
  36.       }//end switch
  37.     }//end if
  38. }//end loop
  39.  
  40.  
  41. void lightLed(byte note, int value){
  42.  if(note>=65 && note<=69){
  43.    digitalWrite(note-63, value);
  44.  }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement