Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte commandByte;
- byte noteByte;
- byte velocityByte;
- byte noteOn = 144;
- //light up led at pin LED_BUILTIN when receiving noteON message with note = 60
- void setup(){
- Serial.begin(31250);
- pinMode(LED_BUILTIN,OUTPUT);
- digitalWrite(LED_BUILTIN,LOW);
- }
- void checkMIDI(){
- do{
- if (Serial.available()){
- commandByte = Serial.read();//read first byte
- noteByte = Serial.read();//read next byte
- velocityByte = Serial.read();//read final byte
- if (commandByte == noteOn){//if note on message
- //check if note == 60 and velocity > 0
- if (velocityByte > 0){
- digitalWrite(LED_BUILTIN,HIGH);//turn on led
- }
- }
- }
- }
- while (Serial.available() > 2);//when at least three bytes available
- }
- void loop(){
- checkMIDI();
- delay(100);
- digitalWrite(LED_BUILTIN,LOW);//turn led off
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement