Advertisement
pleasedontcode

**MIDI Control** rev_03

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