|
|
| (One intermediate revision by the same user not shown) |
| Line 1: |
Line 1: |
| <nowiki>##</nowiki> Setup
| | [[File:Arduino to MIDI guide.pdf|thumb|PDF]] |
| | |
| 1. Install MIDIUSB library <nowiki>https://docs.arduino.cc/libraries/midiusb/</nowiki>
| |
| | |
| 2. Add the MIDIUSB.h Library: Go to Tools < Manage Libraries...
| |
| | |
| 3. Search for "MIDIUSB" by Gary Grewal
| |
| | |
| 4. Install the latest version
| |
| | |
| 5. Select your board: Tools > Board > Arduino Leonardo (or Pro Micro)
| |
| | |
| | |
| 🎛️🎚️ Potentiometers / Sliders
| |
| | |
| <nowiki>###</nowiki> What you need:
| |
| | |
| - 1 potentiometer or slider
| |
| | |
| - 3 wires
| |
| | |
| <nowiki>###</nowiki> How to connect:
| |
| | |
| ```
| |
| | |
| Potentiometer:
| |
| | |
| ├─ Left pin / GND → GND
| |
| | |
| ├─ Middle pin / Signal → A0 (or A1, A2, A3...)
| |
| | |
| └─ Right pin / VCC / Power → 5V
| |
| #include <MIDIUSB.h>
| |
|
| |
| int lastValue = 0;
| |
|
| |
| void setup() {
| |
| pinMode(A0, INPUT); // ← Change A0 to your pin
| |
| }
| |
|
| |
| void loop() {
| |
| int value = analogRead(A0) / 8; // ← Change A0 to match setup
| |
|
| |
| if (value != lastValue) {
| |
| midiEventPacket_t event = {0x0B, 0xB0, 1, value};
| |
| // ↑ ← CC number
| |
| MidiUSB.sendMIDI(event);
| |
| MidiUSB.flush();
| |
| lastValue = value;
| |
| }
| |
|
| |
| delay(10);
| |
| }
| |
| | |
| | |
| | |
| <nowiki>##</nowiki> 🔘 Note button
| |
| | |
| <nowiki>###</nowiki> What you need
| |
| | |
| - 1 push button
| |
| | |
| - 2 wires
| |
| | |
| <nowiki>###</nowiki> How to connect
| |
| | |
| ```
| |
| | |
| Button:
| |
| | |
| ├─ One side → Pin 2 (or 3, 4, 5...)
| |
| | |
| └─ Other side → GND
| |
| | |
| ```
| |
| | |
| #include <MIDIUSB.h>
| |
|
| |
| int lastState = HIGH;
| |
|
| |
| void setup() {
| |
| pinMode(2, INPUT_PULLUP); // ← Change 2 to your pin
| |
| }
| |
|
| |
| void loop() {
| |
| int state = digitalRead(2); // ← Change 2 to match setup
| |
|
| |
| if (state != lastState) {
| |
| if (state == LOW) {
| |
| // Button pressed
| |
| midiEventPacket_t noteOn = {0x09, 0x90, 60, 127};
| |
| // ↑ ↑
| |
| // note velocity
| |
| MidiUSB.sendMIDI(noteOn);
| |
| } else {
| |
| // Button released
| |
| midiEventPacket_t noteOff = {0x08, 0x80, 60, 0};
| |
| // ↑
| |
| // note
| |
| MidiUSB.sendMIDI(noteOff);
| |
| }
| |
| MidiUSB.flush();
| |
| lastState = state;
| |
| }
| |
|
| |
| delay(10);
| |
| }
| |