Skip to content

Instantly share code, notes, and snippets.

@todbot
Created July 9, 2024 15:26
Show Gist options
  • Select an option

  • Save todbot/d34d0b18c2ecfe811aa37f43b5b6c38e to your computer and use it in GitHub Desktop.

Select an option

Save todbot/d34d0b18c2ecfe811aa37f43b5b6c38e to your computer and use it in GitHub Desktop.
Simple MIDI input using MIDI Library on Pico / RP2040 on Arduino
// Simple MIDI input using MIDI Library on Pico
// 2 Mar 2023 - @todbot / Tod Kurt
#include <MIDI.h>
// Serial MIDI, could be "Serial1" or "Serial2" depending on pins on Pico
// See: https://arduino-pico.readthedocs.io/en/latest/serial.html
// and https://pico.pinout.xyz/
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDIserial);
const int serial_rx_pin = 13;
const int serial_tx_pin = 12;
void setup() {
Serial1.setRX(serial_rx_pin);
Serial1.setTX(serial_tx_pin);
MIDIserial.begin(MIDI_CHANNEL_OMNI);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (MIDIserial.read()) {
Serial.printf("type:%x data1:%d data2:%d\n", MIDIserial.getType(), MIDIserial.getData1(), MIDIserial.getData2());
digitalWrite(LED_BUILTIN, HIGH);
delay(10);
digitalWrite(LED_BUILTIN, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment