Advertisement
Guest User

ChatGPT MIDI App

a guest
Sep 10th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <Bounce.h>
  2. #include <MIDI.h>
  3.  
  4. // Create a Bounce object for the button on pin 2
  5. Bounce button = Bounce(2, 10); // 10 ms debounce time
  6.  
  7. // Create a MIDI object
  8. MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
  9.  
  10. void setup() {
  11. // Set pin 2 as input with pullup resistor
  12. pinMode(2, INPUT_PULLUP);
  13.  
  14. // Set pin 4 as output for MIDI
  15. pinMode(4, OUTPUT);
  16.  
  17. // Initialize MIDI communication
  18. MIDI.begin(MIDI_CHANNEL_OMNI);
  19. }
  20.  
  21. void loop() {
  22. // Update the button state
  23. button.update();
  24.  
  25. // Check if the button was pressed
  26. if (button.fallingEdge()) {
  27. // Send MIDI CC 18 with velocity 127 on channel 1
  28. MIDI.sendControlChange(18, 127, 1);
  29. }
  30.  
  31. // Check if the button was released
  32. if (button.risingEdge()) {
  33. // Send MIDI CC 18 with velocity 0 on channel 1
  34. MIDI.sendControlChange(18, 0, 1);
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement