Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bounce.h>
- #include <MIDI.h>
- // Create a Bounce object for the button on pin 2
- Bounce button = Bounce(2, 10); // 10 ms debounce time
- // Create a MIDI object
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
- void setup() {
- // Set pin 2 as input with pullup resistor
- pinMode(2, INPUT_PULLUP);
- // Set pin 4 as output for MIDI
- pinMode(4, OUTPUT);
- // Initialize MIDI communication
- MIDI.begin(MIDI_CHANNEL_OMNI);
- }
- void loop() {
- // Update the button state
- button.update();
- // Check if the button was pressed
- if (button.fallingEdge()) {
- // Send MIDI CC 18 with velocity 127 on channel 1
- MIDI.sendControlChange(18, 127, 1);
- }
- // Check if the button was released
- if (button.risingEdge()) {
- // Send MIDI CC 18 with velocity 0 on channel 1
- MIDI.sendControlChange(18, 0, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement