Advertisement
pleasedontcode

**MIDI Feedback** rev_01

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