Advertisement
pleasedontcode

**MIDI Control** rev_04

Jun 9th, 2025
301
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 20:55:07
  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. ********* User code review feedback **********/
  36.  
  37. /* START CODE */
  38.  
  39. /****** DEFINITION OF LIBRARIES *****/
  40. #include <MIDIUSB.h>    //https://github.com/arduino-libraries/MIDIUSB
  41. #include <Adafruit_NeoPixel.h> // NeoPixel library
  42.  
  43. /****** FUNCTION PROTOTYPES *****/
  44. void setup(void);
  45. void loop(void);
  46.  
  47. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  48. #define NUM_BUTTONS 1 // number of buttons on the controller
  49. #define BUTTON_PIN 2 // pin connected to the buttons
  50. #define NUM_PIXELS 1 // number of NeoPixels on the controller
  51. #define PIXEL_PIN 5 // pin connected to the NeoPixels
  52.  
  53. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800); // initialize NeoPixel object
  54. int buttonState[NUM_BUTTONS]; // array to store button states
  55. int lastButtonState[NUM_BUTTONS]; // array to store last button states
  56.  
  57. void setup(void)
  58. {
  59.     // put your setup code here, to run once:
  60.     pinMode(BUTTON_PIN, INPUT_PULLUP); // set button pin as input with internal pull-up resistor
  61.     pixels.begin(); // initialize NeoPixels
  62. }
  63.  
  64. void loop(void)
  65. {
  66.     // put your main code here, to run repeatedly:
  67.     for (int i = 0; i < NUM_BUTTONS; i++) { // loop through all buttons
  68.         buttonState[i] = digitalRead(BUTTON_PIN + i); // read button state
  69.         if (buttonState[i] != lastButtonState[i]) { // if button state has changed
  70.             if (buttonState[i] == LOW) { // if button is pressed
  71.                 pixels.setPixelColor(i, pixels.Color(255, 255, 255)); // set NeoPixel color to white
  72.                 // Create MIDI note on event
  73.                 midiEventPacket_t noteOn = {0x09, 0x90 | (i + 60), 127, 0}; // Note On message
  74.                 MidiUSB.sendMIDI(noteOn); // send MIDI note on message
  75.             } else { // if button is released
  76.                 pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // turn off NeoPixel
  77.                 // Create MIDI note off event
  78.                 midiEventPacket_t noteOff = {0x09, 0x80 | (i + 60), 0, 0}; // Note Off message
  79.                 MidiUSB.sendMIDI(noteOff); // send MIDI note off message
  80.             }
  81.             pixels.show(); // update NeoPixels
  82.         }
  83.         lastButtonState[i] = buttonState[i]; // store current button state as last button state
  84.     }
  85. }
  86.  
  87. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement