Advertisement
rinaldohack

Untitled

Jul 1st, 2019
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. byte commandByte;
  2. byte noteByte;
  3. byte velocityByte;
  4.  
  5. byte noteOn = 144;
  6.  
  7. //light up led at pin LED_BUILTIN when receiving noteON message with note = 60
  8.  
  9. void setup(){
  10.   Serial.begin(31250);
  11.   pinMode(LED_BUILTIN,OUTPUT);
  12.   digitalWrite(LED_BUILTIN,LOW);
  13. }
  14.  
  15. void checkMIDI(){
  16.   do{
  17.     if (Serial.available()){
  18.       commandByte = Serial.read();//read first byte
  19.       noteByte = Serial.read();//read next byte
  20.       velocityByte = Serial.read();//read final byte
  21.       if (commandByte == noteOn){//if note on message
  22.         //check if note == 60 and velocity > 0
  23.         if (velocityByte > 0){
  24.           digitalWrite(LED_BUILTIN,HIGH);//turn on led
  25.         }
  26.       }
  27.     }
  28.   }
  29.   while (Serial.available() > 2);//when at least three bytes available
  30. }
  31.    
  32.  
  33. void loop(){
  34.   checkMIDI();
  35.   delay(100);
  36.   digitalWrite(LED_BUILTIN,LOW);//turn led off
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement