Advertisement
pleasedontcode

**MIDI Colors** rev_13

Jun 9th, 2025
304
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 Colors**
  13.     - Source Code NOT compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2025-06-09 21:43:01
  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. #### Feedback 8 ####
  45. - code is code is trigering 3 notes simultaneously cc127 cc127 and
  46.  cc0 fix this
  47. #### Feedback 9 ####
  48. - code is trigering 2 notes simultaneously cc127 and cc0 fix this
  49. #### Feedback 10 ####
  50. - when button is pressed code send cc but nothing happens on softw
  51. are
  52. #### Feedback 11 ####
  53. - Compilation error: 'class MIDI_' has no member named 'begin'
  54. #### Feedback 12 ####
  55. - code is trigering 2 notes simultaneously
  56. ********* User code review feedback **********/
  57.  
  58. /* START CODE */
  59.  
  60. /****** DEFINITION OF LIBRARIES *****/
  61. #include <MIDIUSB.h>    //https://github.com/arduino-libraries/MIDIUSB
  62. #include <Adafruit_NeoPixel.h> // NeoPixel library
  63.  
  64. /****** FUNCTION PROTOTYPES *****/
  65. void setup(void);
  66. void loop(void);
  67.  
  68. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  69. #define NUM_BUTTONS 2 // updated to 2 buttons on the controller
  70. #define BUTTON_PIN 2 // pin connected to the buttons
  71. #define NUM_PIXELS 2 // updated to 2 NeoPixels on the controller
  72. #define PIXEL_PIN 5 // pin connected to the NeoPixels
  73.  
  74. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800); // initialize NeoPixel object
  75. int buttonState[NUM_BUTTONS]; // array to store button states
  76. int lastButtonState[NUM_BUTTONS]; // array to store last button states
  77. int activeNote = -1; // variable to store currently active note
  78.  
  79. void setup(void)
  80. {
  81.     // put your setup code here, to run once:
  82.     pinMode(BUTTON_PIN, INPUT_PULLUP); // set button pin as input with internal pull-up resistor
  83.     pixels.begin(); // initialize NeoPixels
  84.     // Removed MidiUSB.begin(); since it does not exist
  85. }
  86.  
  87. void loop(void)
  88. {
  89.     // put your main code here, to run repeatedly:
  90.     for (int i = 0; i < NUM_BUTTONS; i++) { // loop through all buttons
  91.         buttonState[i] = digitalRead(BUTTON_PIN + i); // read button state
  92.         if (buttonState[i] != lastButtonState[i]) { // if button state has changed
  93.             if (buttonState[i] == LOW) { // if button is pressed
  94.                 pixels.setPixelColor(i, pixels.Color(255, 255, 255)); // set NeoPixel color to white
  95.                 // Create MIDI note on event for the pressed note
  96.                 if (activeNote != (i + 60)) { // check if a different note is active
  97.                     if (activeNote != -1) { // if there is an active note, turn it off
  98.                         midiEventPacket_t noteOff = {0x09, 0x80 | activeNote, 0, 0}; // Note Off message for the previously active note
  99.                         MidiUSB.sendMIDI(noteOff); // send MIDI note off message for the previously active note
  100.                     }
  101.                     activeNote = (i + 60); // update active note
  102.                     midiEventPacket_t noteOn = {0x09, 0x90 | activeNote, 127, 0}; // Note On message for the pressed note
  103.                     MidiUSB.sendMIDI(noteOn); // send MIDI note on message for the pressed note
  104.                     MidiUSB.flush(); // ensure the MIDI messages are sent
  105.                 }
  106.             } else { // if button is released
  107.                 pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // turn off NeoPixel
  108.                 if (activeNote == (i + 60)) { // check if the released note is the active note
  109.                     midiEventPacket_t noteOff = {0x09, 0x80 | activeNote, 0, 0}; // Note Off message for the released note
  110.                     MidiUSB.sendMIDI(noteOff); // send MIDI note off message for the released note
  111.                     MidiUSB.flush(); // ensure the MIDI messages are sent
  112.                     activeNote = -1; // reset active note
  113.                 }
  114.             }
  115.             pixels.show(); // update NeoPixels
  116.         }
  117.         lastButtonState[i] = buttonState[i]; // store current button state as last button state
  118.     }
  119. }
  120.  
  121. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement