Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **MIDI Control**
- - Source Code NOT compiled for: Arduino Pro Mini 5V
- - Source Code created on: 2025-06-09 21:22:14
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Utilizes MIDIUSB library to create a MIDI */
- /* controller that can send note and control change */
- /* messages, allowing integration with various MIDI- */
- /* compatible software and hardware. */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - Compilation error: 'MIDI' was not declared in this scope
- #### Feedback 2 ####
- - Compilation error: 'class MIDI_' has no member named 'begin'
- #### Feedback 3 ####
- - Compilation error: 'class MIDI_' has no member named 'sendNoteOn
- '
- #### Feedback 4 ####
- - does not trigger midi notes
- #### Feedback 5 ####
- - trigger 2 notes at the sametime
- #### Feedback 6 ####
- - code do not send any midi
- #### Feedback 7 ####
- - code is not sending midi,when push button on hardware noting hap
- pens
- ********* User code review feedback **********/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <MIDIUSB.h> //https://github.com/arduino-libraries/MIDIUSB
- #include <Adafruit_NeoPixel.h> // NeoPixel library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- #define NUM_BUTTONS 2 // updated to 2 buttons on the controller
- #define BUTTON_PIN 2 // pin connected to the buttons
- #define NUM_PIXELS 2 // updated to 2 NeoPixels on the controller
- #define PIXEL_PIN 5 // pin connected to the NeoPixels
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, PIXEL_PIN, NEO_GRB + NEO_KHZ800); // initialize NeoPixel object
- int buttonState[NUM_BUTTONS]; // array to store button states
- int lastButtonState[NUM_BUTTONS]; // array to store last button states
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(BUTTON_PIN, INPUT_PULLUP); // set button pin as input with internal pull-up resistor
- pixels.begin(); // initialize NeoPixels
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- for (int i = 0; i < NUM_BUTTONS; i++) { // loop through all buttons
- buttonState[i] = digitalRead(BUTTON_PIN + i); // read button state
- if (buttonState[i] != lastButtonState[i]) { // if button state has changed
- if (buttonState[i] == LOW) { // if button is pressed
- pixels.setPixelColor(i, pixels.Color(255, 255, 255)); // set NeoPixel color to white
- // Create MIDI note on event for both notes
- midiEventPacket_t noteOn1 = {0x09, 0x90 | (0 + 60), 127, 0}; // Note On message for first note
- midiEventPacket_t noteOn2 = {0x09, 0x90 | (1 + 60), 127, 0}; // Note On message for second note
- MidiUSB.sendMIDI(noteOn1); // send MIDI note on message for first note
- MidiUSB.sendMIDI(noteOn2); // send MIDI note on message for second note
- MidiUSB.flush(); // ensure the MIDI messages are sent
- } else { // if button is released
- pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // turn off NeoPixel
- // Create MIDI note off event for both notes
- midiEventPacket_t noteOff1 = {0x09, 0x80 | (0 + 60), 0, 0}; // Note Off message for first note
- midiEventPacket_t noteOff2 = {0x09, 0x80 | (1 + 60), 0, 0}; // Note Off message for second note
- MidiUSB.sendMIDI(noteOff1); // send MIDI note off message for first note
- MidiUSB.sendMIDI(noteOff2); // send MIDI note off message for second note
- MidiUSB.flush(); // ensure the MIDI messages are sent
- }
- pixels.show(); // update NeoPixels
- }
- lastButtonState[i] = buttonState[i]; // store current button state as last button state
- }
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement