Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MIDI.h>
- #include <Adafruit_NeoPixel.h>
- // Define the MIDI channel and note number
- const uint8_t midiChannel = 1;
- const uint8_t midiNote = 69;
- // Define the NeoPixel strip
- const uint8_t numberOfPixels = 24;
- const uint8_t pin = 12;
- //creation de l'objet de la bande de led
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(numberOfPixels, pin, NEO_GRB + NEO_KHZ800);
- // Initialize the MIDI library
- MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
- // This function will be called whenever a MIDI message is received
- void onMIDIMessage(byte channel, byte command, byte data1, byte data2) {
- // Only process messages on the specified channel
- if (channel == midiChannel) {
- // If the message is a note on message...
- if (command == NOTE_ON) {
- // ...then set the brightness of the NeoPixels to the velocity of the note
- uint8_t green = (data1 * 255) / 127;
- for (uint8_t i = 0; i < numberOfPixels; i++) {
- strip.setPixelColor(i, green, 0, 0);
- }
- }
- else if (command == NOTE_OFF) {
- // If the message is a note off message...
- stip.clear();
- }
- // Update the NeoPixels
- strip.show();
- }
- }
- void setup() {
- // Initialize the serial port
- Serial.begin(9600);
- // Initialize the MIDI library
- MIDI.begin(MIDI_CHANNEL_OMNI);
- // Attach the onMIDIMessage function to the MIDI library
- MIDI.setHandleNoteOn(onMIDIMessage);
- MIDI.setHandleNoteOff(onMIDIMessage);
- strip.begin();
- strip.show();
- }
- void loop() {
- // Do nothing
- }
Advertisement
Add Comment
Please, Sign In to add comment