cs-midi-docs/docs/examples/03-interfaces/09-send-midi-notes.md

827 B

Send MIDI Notes

Button-driven Note On/Off using the MIDI interface directly, without the element system.

Original: Send-MIDI-Notes.ino

#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include <cs_midi.h>

using namespace cs;

BluetoothMIDI_Interface midi;

AH::Button pushbutton {5};

const MIDIAddress noteAddress {MIDI_Notes::C[4], Channel_1};
const uint8_t velocity = 0x7F;

int main() {
    stdio_init_all();
    if (cyw43_arch_init()) return 1;
    pushbutton.begin();
    midi.begin();
    while (true) {
        midi.update();
        pushbutton.update();
        if (pushbutton.getState() == AH::Button::Falling)
            midi.sendNoteOn(noteAddress, velocity);
        else if (pushbutton.getState() == AH::Button::Rising)
            midi.sendNoteOff(noteAddress, velocity);
    }
}