MIDI to Leds - Fading

Hello,

I'm working on a project where i can send midi input to my Arduino.
I use Ableton, hairlessmidi, processing, loopbe30 and the arduino software.

For me it is already possible to send the midi to the board with the leds.

These are my codes

Processing:
//Import libraries
import processing.serial.;
import promidi.
;

Serial myPort;
MidiIO midiIO;
//Message to be sent
int message=0;

void setup() {
myPort = new Serial(this, "COM5", 9600);
midiIO = MidiIO.getInstance(this);
//Line that prints I/O devices in console
midiIO.printDevices();
//Receive input from Virtual MIDI Ports
midiIO.openInput(0,0);
}

void draw() {}
void noteOn(Note note, int deviceNum, int midiChan){
int vel = note.getVelocity();
int pitch = note.getPitch();
if(vel>0){ // If velocity > 0 set message value to note's pitch
if(pitch==60){ message=60; } else
if(pitch==62){ message=62; } else
if(pitch==64){ message=64; } else
if(pitch==65){ message=65; } else
if(pitch==67){ message=67; } else
if(pitch==69){ message=69; } else message=0;
} else { message=0;}
//Send message to Arduino
myPort.write(message);
}

And the code for Arduino:
// Data received from the serial port
int val;
//LEDs are connected to the following pins
int pins[] = {4,5,6,7,8,9};

void setup() {
for(int i=0; i<6; i++){
pinMode(pins*, OUTPUT); // Set pins as OUTPUTs*

  • }*
  • Serial.begin(9600); // Start serial communication at 9600 bps*
    }

void loop() {
if (Serial.available()) { // If data is available to read,
val = Serial.read(); // read it and store it in val
// Turn on LEDs, depending on pitches received

  • if (val == 60) { digitalWrite(pins[0],HIGH); } else*
  • if (val == 62) { digitalWrite(pins[1],HIGH); } else*
  • if (val == 64) { digitalWrite(pins[2],HIGH); } else*
  • if (val == 65) { digitalWrite(pins[3],HIGH); } else*
  • if (val == 67) { digitalWrite(pins[4],HIGH); } else*
  • if (val == 69) { digitalWrite(pins[5],HIGH); } else*
  • if (val==0) { resetLEDs(); }*
    }
    }
    //Function that turns all the LEDs off
    void resetLEDs(){
  • for(int i=0; i<6; i++){*
    _ digitalWrite(pins*,LOW);_
    _
    }_
    _
    }*_

Now i want to fade the LEDS if the Velocity of the midi is getting higher.
Also i want to connect a servo where i can change the angle when i fade a midi in.
Can somebody help me with this? I don't know how i can write this.
Thank you very much :slight_smile:
Gr, Nylstb

You can only fade LEDs on the six PWM pins using the analogWrite function, if you want more than six LEDs you have to use an external chip.

Servo's are much easier to cope with in siftware as you can simply set the angle on the received velocity, use the map function to convert the values to the right range.

Read the how to use the forum sticky post and learn how to post code here. Before posting again.