Midi inputs as control functions

I have tried for weeks now to link my midi setup (midi shield on top of a uno). To my motor controller (motor shield on a mega). I have the uno flashing to a drum machine beat. I also have motor control using my mega which receives a potentiometer on pin A3 for speed. HOWEVER, I NEED TO LINK THE FLASHING LED TO THE MOTOR SPEED!!! Is this possible?
My photos and code (for uno) are attached.

Just learning how to post correctly so I
have edited my post....
Appreciated any help.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post error messages in code tags as it makes it easier to scroll through them and copy them for examination

Yes, but you would need to decide on the translation of "blink" to "move."

What motor and controller do you have?

Please, do not post pictures of code, rather, post the code, like this...

Thankyou for responses. As i am new. Yes i will try to apply info as stated. I have now used auto format. This is very useful and clearer. My motor controller is the arduino rev3 (controlling a dc motor via external power supply). Mounted on mega 2560 board. Midi shield is Linkspirite, on a unoR3 board.

// this code with a UNOR3 board with MIDI shield on top (linksprite brand).

// MIDI OUT keyboard to MIDI IN shield.
// to receive incoming MIDI on channel 10 (from drum machine on keyboard).
// receiving OK and flashing LED13 to tempo of music beat. ALL GOOD.
//  QUESTION:  HOW DO I CONVERT THIS FLASHING LED TO CONTROL THE SPEED OF A SMALL DC MOTOR?
// assume I need to somehow map the flashing signal? to produce and output voltage (0-255)?
// Note also ..  the motor is driven by an Arduino motor controller REV3 sitting atop another Mega 2650 board (usually
// getting speed data from a potentiometer into A3).

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define LED_PIN 13;

void setup() {
  pinMode(13, OUTPUT);

  Serial.begin(31250);
  MIDI.begin();  // Launch MIDI and listen to channels
}
void loop() {

  if (MIDI.read(10))
    ;  // If we have received a message
  {
    switch (MIDI.getType()) {
      case midi::NoteOn:
        digitalWrite(13, HIGH);
        delay(10);

      case midi::NoteOff:
        digitalWrite(13, LOW);
        delay(10);

        // WHAT NOW?  to send motor speed control instruction to my mega board (which drives 5 volt dc motor via external power)
    }
  }
}
![midi shield on unor3|375x500](upload://dMtHbKaNKxuUgdmHgkIUSp6Ftzn.jpeg)
![arduino motor shield on mega2650|375x500](upload://wFXiScc7roHIQr0XWJ6RNrWE9St.jpeg)

Before proceding, for protection of your Arduino, would you show a wiring diagram? Your text sounds like you do not have circuit protection around the motor, and are driving the DC motor directly from the Arduino.

No. Motor driven by external power supply. I will sort out a diagram now.

Motors need a circuit (or a motor driver module). Here is a drawing from @gilshultz showing a pulldown resistor for the controlling pin, a bias resistor for the gate of the MOSFET for driving the motor, and a diode to suppress feedback (flyback) from the motor.

Quick question so i do it correctly on the Forum. What is easiest way to add a diagram?

ok hope I am doing this correctly. wiring diagram. plus 2 codes. one for each board.`

type or paste code here
![20250402_111438 (1)|375x500](upload://f4BrQf3QI4DURlmroYygVwgPUob.jpeg)

FIRST CODE UNO

// this code with a UNOR3 board with MIDI shield on top (linksprite brand).

// MIDI OUT keyboard to MIDI IN shield.
// to receive incoming MIDI on channel 10 (from drum machine on keyboard).
// receiving OK and flashing LED13 to tempo of music beat. ALL GOOD.

// QUESTION: HOW DO I CONVERT THIS FLASHING LED TO CONTROL THE SPEED OF A SMALL DC MOTOR?
// assume I need to somehow map the flashing signal? to produce and output voltage (0-255)?

// Note also .. the motor is driven by a second Arduino MEGA board with Arduino REV3 motor controller sitting atop.

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define LED_PIN 13;

void setup() {
pinMode(13, OUTPUT);

Serial.begin(31250);
MIDI.begin(); // Launch MIDI and listen to channels
}
void loop() {

if (MIDI.read(10))
; // If we have received a message
{
switch (MIDI.getType()) {
case midi::NoteOn:
digitalWrite(13, HIGH);
delay(10);

  case midi::NoteOff:
    digitalWrite(13, LOW);
    delay(10);
SECOND CODE MEGA

// MEGA board. Arduino REV3 motor shield on top. One DC motor (5 volts) with external power supply via shield.

#include <AFMotor.h>

int speedPotPin3 = A3; // speed of DC motor via potentiometer on A3
int speed3;

void setup() {

//Setup Channel A.
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin

Serial.begin(9600); // Initialize serial communication
}
void loop() {

speed3 = map(analogRead(speedPotPin3), 0, 1023, 0, 255);

digitalWrite(12, HIGH); // motor A : DIRECTION clockwise
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, speed3); //Spins the motor on Channel A at stated speed via INPUT A3 (potentiometer)
delay(200);

Serial.println(speed3);
delay(50);
}

[TEST_ArduinoShieldREV3_1DCmotor.ino|attachment](upload://anEMw6JkBbMunsumvo2Y2Vt2KZf.ino) (786 Bytes)

Not sure my diagram uploaded I will try again.
![20250402_111438 (1)|375x500](upload://f4BrQf3QI4DURlmroYygVwgPUob.jpeg)

![20250402_111438 (1)|375x500](upload://f4BrQf3QI4DURlmroYygVwgPUob.jpeg)
![20250402_111438 (1)|375x500](upload://f4BrQf3QI4DURlmroYygVwgPUob.jpeg)
![20250402_111438 (1)|375x500](upload://f4BrQf3QI4DURlmroYygVwgPUob.jpeg)

To add a diagram, click the button that looks like abox with an up-arrow.

You need to wrap your code in a code block.

I have tried for weeks now to link my midi setup (midi shield on top of a uno). To my motor controller (motor shield on a mega). I have the uno flashing to a drum machine beat. I also have motor control using my mega which receives a potentiometer on pin A3 for speed. HOWEVER, I NEED TO LINK THE FLASHING LED TO THE MOTOR SPEED!!! Is this possible?
My photos and code (for uno) are attached.

Just learning how to post correctly so I
have edited my post....
Appreciated any help.


```cpp

// MEGA board. Arduino REV3 motor shield on top.  One DC motor  (5 volts) with external power supply via shield.

#include <AFMotor.h>

int speedPotPin3 = A3;  // speed of DC motor via potentiometer on A3
int speed3;

void setup() {

  //Setup Channel A.
  pinMode(12, OUTPUT);  //Initiates Motor Channel A pin
  pinMode(9, OUTPUT);   //Initiates Brake Channel A pin

  Serial.begin(9600);  // Initialize serial communication
}
void loop() {

  speed3 = map(analogRead(speedPotPin3), 0, 1023, 0, 255);

  digitalWrite(12, HIGH);  // motor A : DIRECTION clockwise
  digitalWrite(9, LOW);    //Disengage the Brake for Channel A
  analogWrite(3, speed3);  //Spins the motor on Channel A at stated speed via INPUT A3 (potentiometer)
  delay(200);

  Serial.println(speed3);
  delay(50);
}

```cpp
// this code with a UNOR3 board with MIDI shield on top (linksprite brand).

// MIDI OUT keyboard to MIDI IN shield.
// to receive incoming MIDI on channel 10 (from drum machine on keyboard).
// receiving OK and flashing LED13 to tempo of music beat. ALL GOOD.

//  QUESTION:  HOW DO I CONVERT THIS FLASHING LED TO CONTROL THE SPEED OF A SMALL DC MOTOR?
// assume I need to somehow map the flashing signal? to produce and output voltage (0-255)?

// Note also ..  the motor is driven by a second Arduino MEGA board with Arduino REV3 motor controller sitting atop.

#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define LED_PIN 13;

void setup() {
  pinMode(13, OUTPUT);

  Serial.begin(31250);
  MIDI.begin();  // Launch MIDI and listen to channels
}
void loop() {

  if (MIDI.read(10))
    ;  // If we have received a message
  {
    switch (MIDI.getType()) {
      case midi::NoteOn:
        digitalWrite(13, HIGH);
        delay(10);

      case midi::NoteOff:
        digitalWrite(13, LOW);
        delay(10);

        // WHAT NOW?  to send motor speed control instruction to my mega board (which drives 5 volt dc motor via external power)
    }
  }
}

Use code tags to format code for the forum

I already answered that. Why are you ignoring that? Are you begging for someone to do your work? Do you think asking again because you don't like the answer will find someone to do your work? Read posts #3, 8, 11, 12.

Do you mean the diagram you sent me?

I have a motor shield so i thought i had that covered!

A motor shield has the protection circuit.

So i am still not sure were the answer was that i missed. The misunderstanding will be mine! Apologies

Is it that i need to decide on the translation of "blink" to "move."?

You should have some means of translating a blink to a motor movement.