generated from madskjeldgaard/raspberry-pi-pico-usbmidi-platformio-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4581395
commit c42589f
Showing
2 changed files
with
40 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,53 @@ | ||
#include <Arduino.h> | ||
#include <Adafruit_TinyUSB.h> | ||
#include <Arduino.h> | ||
#include <MIDI.h> | ||
|
||
#include <Bounce2.h> | ||
Bounce2::Button sustainPedal1 = Bounce2::Button(); | ||
|
||
constexpr auto SUSTAIN_PIN = 0; | ||
constexpr auto MIDI_NOTE = 48; | ||
constexpr auto MIDI_VELOCITY = 127; | ||
constexpr auto TO_CHANNEL = 1; | ||
|
||
constexpr auto PIN = SUSTAIN_PIN; | ||
constexpr auto PIN_MODE = INPUT_PULLUP; | ||
constexpr auto INTERVAL_IN_MS = 5; | ||
|
||
// USB MIDI object | ||
Adafruit_USBD_MIDI usbMidi; | ||
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usbMidi, MIDI); | ||
|
||
static bool toggle_state1 = false; | ||
|
||
void handle_sustain() { | ||
sustainPedal1.update(); | ||
|
||
if (sustainPedal1.pressed()) { | ||
|
||
if (toggle_state1) { | ||
MIDI.sendNoteOn(MIDI_NOTE, MIDI_VELOCITY, TO_CHANNEL); | ||
} else { | ||
MIDI.sendNoteOff(MIDI_NOTE, 0, TO_CHANNEL); | ||
} | ||
|
||
toggle_state1 = !toggle_state1; | ||
} | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.println("Hello World!"); | ||
|
||
TinyUSBDevice.setManufacturerDescriptor("MadsKjeldgaard"); | ||
TinyUSBDevice.setProductDescriptor("Pico Blinkity Blinky"); | ||
TinyUSBDevice.setProductDescriptor("Sustain2Midi"); | ||
|
||
usbMidi.begin(); | ||
MIDI.begin(); | ||
|
||
pinMode(LED_BUILTIN, OUTPUT); | ||
digitalWrite(LED_BUILTIN, 1); | ||
// Setup button | ||
sustainPedal1.attach(PIN, PIN_MODE); | ||
sustainPedal1.interval(INTERVAL_IN_MS); | ||
sustainPedal1.setPressedState(LOW); | ||
} | ||
|
||
auto pastLEDState = true; | ||
void loop() { | ||
Serial.println("Hello from da loop!"); | ||
|
||
// Blink the LED | ||
digitalWrite(LED_BUILTIN, static_cast<int>(pastLEDState)); | ||
|
||
// Send a midi note | ||
if(pastLEDState){ | ||
MIDI.sendNoteOn(60, 127, 1); | ||
} else { | ||
MIDI.sendNoteOff(60, 0, 1); | ||
} | ||
|
||
pastLEDState = !pastLEDState; | ||
|
||
delay(500); | ||
} | ||
void loop() { handle_sustain(); } |