Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. /*
  2. MIDI note on messages with variable velocity
  3. By Amanda Ghassaei
  4. July 2012
  5. https://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/
  6.  
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  
  12. */
  13.  
  14. #include <HardwareSerial.h>
  15.  
  16. HardwareSerial mySerial(1);
  17.  
  18. int noteON = 144;//144 = 10010000 in binary, note on command
  19.  
  20. void setup() {
  21.   //  Set MIDI baud rate:
  22.   Serial.begin(115200);
  23.   mySerial.begin(115200, SERIAL_8N1, 26, 27);
  24.  
  25.   delay(1000);
  26.  
  27.   mySerial.println("--------STARTING---------");
  28. }
  29.  
  30. void loop() {
  31.   int velocity = 20;//set velocity to 20
  32.  
  33.     MIDImessage(noteON, 50, velocity);//turn note on
  34.     velocity += 5;//ad 5 to current velocity value
  35.  
  36.  
  37.   mySerial.println("LOOPING");
  38.  
  39.   while(Serial.available()>0)
  40.     {
  41.       byte incomingByte = Serial.read();
  42.  
  43.       mySerial.print("I received: ");
  44.       mySerial.println(incomingByte, DEC);
  45.     };
  46.  
  47.     delay(100);
  48. }
  49.  
  50. //send MIDI message
  51. void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
  52.   Serial.write(command);//send note on or note off command
  53.   //Serial.write(MIDInote);//send pitch data
  54.   Serial.write(MIDIvelocity);//send velocity data
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement