Skip to content

Instantly share code, notes, and snippets.

@Gkiokan
Created June 24, 2023 22:38
Show Gist options
  • Save Gkiokan/cb3878593f6edc51e857d555166fa99d to your computer and use it in GitHub Desktop.
Save Gkiokan/cb3878593f6edc51e857d555166fa99d to your computer and use it in GitHub Desktop.
midi demo
#include <MIDI.h>
const int channel = 0;
const int wheelPin = A2;
int wheel = 0;
int mappedWheel = 0;
int maxPitchValue = 16383;
// Probably fix for Hairless as it seems to run on 115200 but didn't helped me
// struct HairlessMidiSettings : public midi::DefaultSettings
// {
// static const bool UseRunningStatus = false;
// static const long BaudRate = 31250; // 115200;
// };
// MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, HairlessMidiSettings);
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
MIDI.begin();
// Serial.begin(9600);
// Serial.begin(31250);
}
void loop() {
wheel = analogRead(wheelPin);
mappedWheel = map(wheel, 0, 1023, 0, 127);
Serial.println("Pitch Bend Value ");
Serial.println(mappedWheel);
delay(1000);
// MIDI.sendPitchBend(mappedWheel, channel+1);
// MIDI.sendControlChange(1, mappedWheel, 1);
// sendPitchBend(mappedWheel, channel);
}
void sendPitchBend(int value, int channel) {
// Calculate the MSB (most significant byte) and LSB (least significant byte) of the pitch bend value
byte lsb = value & 0x7F;
byte msb = (value >> 7) & 0x7F;
// Construct and send the MIDI pitch bend command
// Serial.println(lsb);
// Serial.println(msb);
// Serial.println("-");
// sendMIDICommand(0xE0, lsb, msb);
sendMIDICommand(0xE0|channel, lsb, msb);
}
void sendMIDICommand(byte command, byte data1, byte data2) {
Serial.write(command);
Serial.write(data1);
Serial.write(data2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment