Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- MIDI note on messages with variable velocity
- By Amanda Ghassaei
- July 2012
- https://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- */
- #include <HardwareSerial.h>
- HardwareSerial mySerial(1);
- int noteON = 144;//144 = 10010000 in binary, note on command
- void setup() {
- // Set MIDI baud rate:
- Serial.begin(115200);
- mySerial.begin(115200, SERIAL_8N1, 26, 27);
- delay(1000);
- mySerial.println("--------STARTING---------");
- }
- void loop() {
- int velocity = 20;//set velocity to 20
- MIDImessage(noteON, 50, velocity);//turn note on
- velocity += 5;//ad 5 to current velocity value
- mySerial.println("LOOPING");
- while(Serial.available()>0)
- {
- byte incomingByte = Serial.read();
- mySerial.print("I received: ");
- mySerial.println(incomingByte, DEC);
- };
- delay(100);
- }
- //send MIDI message
- void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
- Serial.write(command);//send note on or note off command
- //Serial.write(MIDInote);//send pitch data
- Serial.write(MIDIvelocity);//send velocity data
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement