Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
madskjeldgaard committed May 9, 2024
1 parent 4581395 commit c42589f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
4 changes: 4 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ lib_deps =
Adafruit TinyUSB Library
# MIDI
https://github.com/FortySevenEffects/arduino_midi_library
# Button debounce
thomasfredericks/Bounce2@^2.72



[env:raspberrypi-pico]
; See https://arduino-pico.readthedocs.io/en/latest/platformio.html
Expand Down
59 changes: 36 additions & 23 deletions src/main.cpp
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(); }

0 comments on commit c42589f

Please sign in to comment.