Advertisement
pleasedontcode

**MIDI Control** rev_08

Jun 9th, 2025
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **MIDI Control**
  13.     - Source Code NOT compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2025-06-09 21:22:14
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Utilizes MIDIUSB library to create a MIDI */
  21.     /* controller that can send note and control change */
  22.     /* messages, allowing integration with various MIDI- */
  23.     /* compatible software and hardware. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /********* User code review feedback **********
  28. #### Feedback 1 ####
  29. - Compilation error: 'MIDI' was not declared in this scope
  30. #### Feedback 2 ####
  31. - Compilation error: 'class MIDI_' has no member named 'begin'
  32. #### Feedback 3 ####
  33. - Compilation error: 'class MIDI_' has no member named 'sendNoteOn
  34. '
  35. #### Feedback 4 ####
  36. - does not trigger midi notes
  37. #### Feedback 5 ####
  38. - trigger 2 notes at the sametime
  39. #### Feedback 6 ####
  40. - code do not send any midi
  41. #### Feedback 7 ####
  42. - code is not sending midi,when push button on hardware noting hap
  43. pens
  44. ********* User code review feedback **********/
  45.  
  46. /* START CODE */
  47.  
  48. /****** DEFINITION OF LIBRARIES *****/
  49. #include <MIDIUSB.h>    //https://github.com/arduino-libraries/MIDIUSB
  50. #include <Adafruit_NeoPixel.h> // NeoPixel library
  51.  
  52. /****** FUNCTION PROTOTYPES *****/
  53. void setup(void);
  54. void loop(void);
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57. #define NUM_BUTTONS 2 // updated to 2 buttons on the controller
  58. #define BUTTON_PIN 2 // pin connected to the buttons
  59. #define NUM_PIXELS 2 // updated to 2 NeoPixels on the controller
  60. #define PIXEL_PIN 5 // pin connected to the NeoPixels
  61.  
  62. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800); // initialize NeoPixel object
  63. int buttonState[NUM_BUTTONS]; // array to store button states
  64. int lastButtonState[NUM_BUTTONS]; // array to store last button states
  65.  
  66. void setup(void)
  67. {
  68.     // put your setup code here, to run once:
  69.     pinMode(BUTTON_PIN, INPUT_PULLUP); // set button pin as input with internal pull-up resistor
  70.     pixels.begin(); // initialize NeoPixels
  71. }
  72.  
  73. void loop(void)
  74. {
  75.     // put your main code here, to run repeatedly:
  76.     for (int i = 0; i < NUM_BUTTONS; i++) { // loop through all buttons
  77.         buttonState[i] = digitalRead(BUTTON_PIN + i); // read button state
  78.         if (buttonState[i] != lastButtonState[i]) { // if button state has changed
  79.             if (buttonState[i] == LOW) { // if button is pressed
  80.                 pixels.setPixelColor(i, pixels.Color(255, 255, 255)); // set NeoPixel color to white
  81.                 // Create MIDI note on event for both notes
  82.                 midiEventPacket_t noteOn1 = {0x09, 0x90 | (0 + 60), 127, 0}; // Note On message for first note
  83.                 midiEventPacket_t noteOn2 = {0x09, 0x90 | (1 + 60), 127, 0}; // Note On message for second note
  84.                 MidiUSB.sendMIDI(noteOn1); // send MIDI note on message for first note
  85.                 MidiUSB.sendMIDI(noteOn2); // send MIDI note on message for second note
  86.                 MidiUSB.flush(); // ensure the MIDI messages are sent
  87.             } else { // if button is released
  88.                 pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // turn off NeoPixel
  89.                 // Create MIDI note off event for both notes
  90.                 midiEventPacket_t noteOff1 = {0x09, 0x80 | (0 + 60), 0, 0}; // Note Off message for first note
  91.                 midiEventPacket_t noteOff2 = {0x09, 0x80 | (1 + 60), 0, 0}; // Note Off message for second note
  92.                 MidiUSB.sendMIDI(noteOff1); // send MIDI note off message for first note
  93.                 MidiUSB.sendMIDI(noteOff2); // send MIDI note off message for second note
  94.                 MidiUSB.flush(); // ensure the MIDI messages are sent
  95.             }
  96.             pixels.show(); // update NeoPixels
  97.         }
  98.         lastButtonState[i] = buttonState[i]; // store current button state as last button state
  99.     }
  100. }
  101.  
  102. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement