DIY MIDI USB CONTROLEUR Project Arduino Uno Besoin d'aide

Bonjour a tous

Il semblerait que ma carte soit HS

je peux programmer via le logiciel Arduino ,la carte est bien reconnu par le port USB ,et je peux également flasher le contrôleur USB ATMEGA16U2 via le logiciel FLIP

Mais lorsque je manipule la carte les diodes s'allume aléatoirement comme si il y a avait un mauvais contact le truc c'est qu'il n'y a rien de branché

Mon projet est de réaliser un controleur MIDI
Via le logiciel Hairless Midi j'ai un erreur des que je commence a transmettre étant donner que la transmission s'effectue en permanence

Lors de mes premier test je n'avais pas ce problème la

Ci joint voici les programmes ainsi que les projets dont je me suis inspiré

je vous remercie par avance pour votre aide

Bonjour

Je pense qu'il vaudrait mieux poster votre code directement sur ce site.

les diodes s'allume aléatoirement

LES diodes ou uniquement LA diode Tx ?

Cordialement,
bidouilleelec

Si le logiciel de la carte envoie des Serial.print, c'est normal que la LED TX clignote.
Ouvrir le moniteur série pour voir.

La diode TX reste allumé

La led Power est allumé

la diode L est etteinte
mais des que je manipule la carte les diodes TX et LED clignote
La diode RX reste etteinte

Voici le code :

#include <MIDI.h>  // INlcude MIDI library

const int buttonPin = 2;  // the number of the Button pin
const int buttonPin2 = 3;
const int buttonPin3 = 4; 
const int buttonPin4 = 5;
const int buttonPin5 = 6; 
const int buttonPin6 = 7;
const int buttonPin7 = 8; 
const int buttonPin8 = 9;
// the number of the pushbutton pin
const int ledPin =  11;      // the number of the LED pin
const int ledPin2 =  12;
const int ledPin3 =  13;     
const int ledPin4 =  14;
const int ledPin5 =  15;    
const int ledPin6 =  16;
const int ledPin7 =  17;     
const int ledPin8 =  18;

// variables will change:
boolean currentState = LOW;//stroage for current button state
boolean lastState = LOW;//storage for last button state
boolean currentState2 = LOW;
boolean lastState2 = LOW;
boolean currentState3 = LOW;
boolean lastState3 = LOW;
boolean currentState4 = LOW;
boolean lastState4 = LOW;
boolean currentState5 = LOW;
boolean lastState5 = LOW;
boolean currentState6 = LOW;
boolean lastState6 = LOW;
boolean currentState7 = LOW;
boolean lastState7 = LOW;
boolean currentState8 = LOW;
boolean lastState8 = LOW;

void setup() {
 
 Serial.begin(31250);  // default midi speed rate
 
 // initialize the LED pin as an output:
 pinMode(ledPin, OUTPUT);      
 // initialize the pushbutton pin as an input:
 pinMode(buttonPin, INPUT); 
 
 pinMode(ledPin2, OUTPUT);      
 pinMode(buttonPin2, INPUT);
 
  pinMode(ledPin3, OUTPUT);      
 pinMode(buttonPin3, INPUT); 
 
 pinMode(ledPin4, OUTPUT);      
 pinMode(buttonPin4, INPUT);  
 
  pinMode(ledPin5, OUTPUT);      
 pinMode(buttonPin5, INPUT); 
 
 pinMode(ledPin6, OUTPUT);      
 pinMode(buttonPin6, INPUT); 
 
  pinMode(ledPin7, OUTPUT);      
 pinMode(buttonPin7, INPUT); 
 
 pinMode(ledPin8, OUTPUT);      :
 pinMode(buttonPin8, INPUT);  
 
MIDI.begin(); 
}
 int iAn0Val, iAn1Val, iAn2Val, iAn3Val, iAn4Val, iAn5Val;

void loop(){
 
 // read the state of the pushbutton value:

 currentState = digitalRead(buttonPin);
 // check if the pushbutton is pressed.
 
 // if it is, the buttonState is HIGH:
 if (currentState == LOW && lastState == HIGH) { 
   
   digitalWrite(ledPin,HIGH); 
     
     MIDI.sendNoteOff(42,0,1);
   // turn LED off   
    
 } 
 
 else if (currentState == HIGH && lastState == LOW) { 
   digitalWrite(ledPin, LOW); 
   MIDI.sendNoteOn(42,127,1);
   // turn LED on
   delay(20);
   MIDI.sendNoteOff(42,0,1);
   // turn LED off 
 }
 
 lastState = currentState;            
 
   currentState2 = digitalRead(buttonPin2);

 if (currentState2 == LOW && lastState2 == HIGH) {
   digitalWrite(ledPin2,HIGH);  
    MIDI.sendNoteOff(39,0,1);
 } 
 else if (currentState2 == HIGH && lastState2 == LOW) {
  digitalWrite(ledPin2, LOW); 
  MIDI.sendNoteOn(39,127,1);
  delay(20);
     MIDI.sendNoteOff(39,0,1);
    }  
    lastState2 = currentState2;      
    
        currentState3 = digitalRead(buttonPin3);

 if (currentState3 == LOW && lastState3 == HIGH) {
   digitalWrite(ledPin3,HIGH);  
     MIDI.sendNoteOff(40,0,1);
 } 
 else if (currentState3 == HIGH && lastState3 == LOW) {
   
   digitalWrite(ledPin3, LOW); 
   MIDI.sendNoteOn(40,127,1);
   delay(20);
     MIDI.sendNoteOff(40,0,1);
    }  
    lastState3 = currentState3;
    
        currentState4 = digitalRead(buttonPin4);

 if (currentState4 == LOW && lastState4 == HIGH) {
   
   digitalWrite(ledPin4,HIGH);  
     
     MIDI.sendNoteOff(41,0,1);
   
 } 
 else if (currentState4 == HIGH && lastState4 == LOW) {
   
    digitalWrite(ledPin4, LOW); 
   MIDI.sendNoteOn(41,127,1);
    
  delay(20);
     MIDI.sendNoteOff(41,0,1);
    }  
    lastState4 = currentState4;
    
        currentState5 = digitalRead(buttonPin5);

 if (currentState5 == LOW && lastState5 == HIGH) {
   
   digitalWrite(ledPin5,HIGH);  
     
     MIDI.sendNoteOff(38,0,1);
   
 } 
 else if (currentState5 == HIGH && lastState5 == LOW) {
   
    digitalWrite(ledPin5, LOW); 
   MIDI.sendNoteOn(38,127,1);
    
  delay(20);
     MIDI.sendNoteOff(38,0,1);
    }  
    lastState5 = currentState5;
    
        currentState6 = digitalRead(buttonPin6);

 if (currentState6 == LOW && lastState6 == HIGH) {
   
   digitalWrite(ledPin6,HIGH);  
     
     MIDI.sendNoteOff(43,0,1);
   
 } 
 else if (currentState6 == HIGH && lastState6 == LOW) {
   
    digitalWrite(ledPin6, LOW); 
   MIDI.sendNoteOn(43,127,1);

  delay(20);
     MIDI.sendNoteOff(43,0,1);
    }  
    lastState6 = currentState6;
    
        currentState7 = digitalRead(buttonPin7);

 if (currentState7 == LOW && lastState7 == HIGH) {
   
   digitalWrite(ledPin7,HIGH);  
     
     MIDI.sendNoteOff(37,0,1);
   
 } 
 else if (currentState7 == HIGH && lastState7 == LOW) {
   
    digitalWrite(ledPin7, LOW); 
   MIDI.sendNoteOn(37,127,1);

  delay(20);
     MIDI.sendNoteOff(37,0,1);
    }  
    lastState7 = currentState7;
    
        currentState8 = digitalRead(buttonPin8);

 if (currentState8 == LOW && lastState8 == HIGH) {
   
   digitalWrite(ledPin8,HIGH);  
     
     MIDI.sendNoteOff(44,0,1);
   
 } 
 else if (currentState8 == HIGH && lastState8 == LOW) {
   
    digitalWrite(ledPin8, LOW); 
   MIDI.sendNoteOn(44,127,1);

  delay(20);
     MIDI.sendNoteOff(44,0,1);
    }  
    lastState8 = currentState8;
    
     int iAn0ValPrev = iAn0Val; // previous value
  iAn0Val = analogRead(A0)/8; // Divide by 8 to get range of 0-127 for midi
  analogPinMidiTX(1,iAn0Val,iAn0ValPrev); //TX value 
  
  int iAn1ValPrev = iAn1Val; 
  iAn1Val = analogRead(A1)/8;
  analogPinMidiTX(2,iAn1Val,iAn1ValPrev); 
  
  int iAn2ValPrev = iAn2Val; 
  iAn2Val = analogRead(A2)/8;
  analogPinMidiTX(3,iAn2Val,iAn2ValPrev);
  
  int iAn3ValPrev = iAn3Val; 
  iAn3Val = analogRead(A3)/8;
  analogPinMidiTX(4,iAn3Val,iAn3ValPrev); 
  
  int iAn4ValPrev = iAn4Val; 
  iAn4Val = analogRead(A4)/8;
  analogPinMidiTX(5,iAn4Val,iAn4ValPrev); 
  
  int iAn5ValPrev = iAn5Val; 
  iAn5Val = analogRead(A5)/8;
  analogPinMidiTX(6,iAn5Val,iAn5ValPrev); 
 
}

void analogPinMidiTX(int iChan, int iVal, int iValPrev)
{  
 // TX Value only if it has changed
 if(iValPrev != iVal)
 {
   MidiTX(176,iChan,iVal); // 176 = CC command, 1 = Which Control, val = value read from Potentionmeter
 }
}

void MidiTX(unsigned char MESSAGE, unsigned char CONTROL, unsigned char VALUE) //Valeur en Midi Command
{
  Serial.write(MESSAGE);
  Serial.write(CONTROL);
  Serial.write(VALUE);
}

État du Moniteur Série

Tu aurais pu lire ça : Bien editer son post pour les nuls - Français - Arduino Forum au lieu de balancer des tartines de code dans le texte du topic.

Pense aux gens qui lisent sur un smartphone.

 pinMode(buttonPin, INPUT);

Si tu n'a pas branché de résistance de PULLUP, la pin est en l'air.

 pinMode(buttonPin, INPUT_PULLUP);

Ou branche une résistance de qq K minimum entre pin et masse si tu veux conserver une logique positive.

@+

Merci pour ta reponse Hbachetti
et désolé pour le post du code je ne manquerai pas de regarder le topic indiqué avant de poster un prochain code

J'ai effectivement modifié le code et je n'ai plus ce problème de pin en l'air

les résistances sont bien sur mon montage final j'ai retiré la carte pour tester uniquement les potentiomètres

Concernant ces potentiomètres ils fonctionnent aléatoirement mais lorsque je fais mon mapping midi dans mon logiciel Mao
ils fonctionnent aléatoirement et leur course est différente
de plus la Diode TX clignote par moment sans rien toucher rendant impossible le prochain parametrage midi

Les potentiomètre en question sont des 10kHOM

Est ce qu'il y a quelque chose a mettre en entre le potentiomètre et l'entre analogique?
Ou bien le code concernant les potentiomètres et erroné?

Bonjour

désolé pour le post du code je ne manquerai pas de regarder le topic indiqué avant de poster un prochain code

il est très facile de corriger la présentation du code déjà posté (en ajoutant les balsies de début et de fin)
tel quel il ya aura peu de lecteurs......

     int iAn0ValPrev = iAn0Val; // previous value

Je suppose que iAn0ValPrev, iAn1ValPrev, etc. sont sensées conserver l'ancienne valeur.
Une variable locale est recréée à chaque passage dans la fonction et prend la valeur que les cases mémoire ont à ce moment là dans la pile ou le registre. D'où les valeurs "n'importe quoi" que tu observes.

Il faudrait les déclarer en global ou static.

     static int iAn0ValPrev;
     iAn0ValPrev = iAn0Val; // previous value
     // etc.

@+

il y a du mieux en déclarant en static les variables
je peux mapper mes potentiomètres mais il faut qu'ils soient tous tournés en buté minimum
sauf pour le dernier que je mappe
le prochain mappage sont donc impossible
mais une fois mappé la course des potentiomètres est différentes et les valeurs changent des facons aléatoires sans rien toucher

Les potentiomètres ne fonctionnent toujours pas
Leur course est différente
Leur mappage en midi est impossible car selon la position des potentiomètres la diode TX clignote en permanence
Même si je reussie a mappé un ou 2 potentiomètres le mappage des autres est impossible
Car des que je touche un autre potentiomètres la diode TX clignote donc le mappage est aléatoire

En pieces jointes vous trouverez mon schema de câblage

Et ci dessous la bibliothèque Midi que j'utilise

#include <MIDI.h>
/*
  Basic I/O MIDI tutorial
  by Franky
  28/07/2009
*/

#define LED 13   		// LED pin on Arduino board

void setup() {
  pinMode(LED, OUTPUT);
  MIDI.begin(4);            	// Launch MIDI with default options
				// input channel is set to 4
}

void loop() {
  if (MIDI.read()) {
    digitalWrite(LED,HIGH);     // Blink the LED
    MIDI.sendNoteOn(42,127,1);  // Send a Note (pitch 42, velo 127 on channel 1)
    delay(1000);		// Wait for a second
    MIDI.sendNoteOff(42,0,1);   // Stop the note
    digitalWrite(LED,LOW);    	
  }
}
#include <MIDI.h>


// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,
// see documentation here: 
// http://arduinomidilib.sourceforge.net/class_m_i_d_i___class.html

void HandleNoteOn(byte channel, byte pitch, byte velocity) { 

  // Do whatever you want when you receive a Note On.
  
  if (velocity == 0) {
    // This acts like a NoteOff.
  }

  // Try to keep your callbacks short (no delays ect) as the contrary would slow down the loop()
  // and have a bad impact on real-time performance.
}

void setup() {
  // Initiate MIDI communications, listen to all channels
  MIDI.begin(MIDI_CHANNEL_OMNI);    
  
  // Connect the HandleNoteOn function to the library, so it is called upon reception of a NoteOn.
  MIDI.setHandleNoteOn(HandleNoteOn);  // Put only the name of the function
  
}


void loop() {
  // Call MIDI.read the fastest you can for real-time performance.
  MIDI.read();
  
  // There is no need to check if there are messages incoming if they are bound to a Callback function.
}
#include <MIDI.h>
/*
  MIDI Input tutorial
  by Franky
  28/07/2009
  
  NOTE: for easier MIDI input reading, 
  take a look a the Callbacks example.
  
*/

#define LED 13   		// LED pin on Arduino board

void BlinkLed(byte num) { 	// Basic blink function
  for (byte i=0;i<num;i++) {
    digitalWrite(LED,HIGH);
    delay(50);
    digitalWrite(LED,LOW);
    delay(50);
  }
}


void setup() {
  pinMode(LED, OUTPUT);
  MIDI.begin();            	// Launch MIDI with default options
				// (input channel is default set to 1)
}

void loop() {
  if (MIDI.read()) {                    // Is there a MIDI message incoming ?
    switch(MIDI.getType()) {		// Get the type of the message we caught
      case ProgramChange:               // If it is a Program Change
	BlinkLed(MIDI.getData1());	// Blink the LED a number of times 
					// correponding to the program number 
					// (0 to 127, it can last a while..)
        break;
      // See the online reference for other message types
      default:
        break;
    }
  }
}

TheWholeCulture:
Les potentiomètres ne fonctionnent toujours pas
Leur course est différente
Leur mappage en midi est impossible car selon la position des potentiomètres la diode TX clignote en permanence
Même si je reussie a mappé un ou 2 potentiomètres le mappage des autres est impossible
Car des que je touche un autre potentiomètres la diode TX clignote donc le mappage est aléatoire

Bonsoir
Je n'ai pas regardé ton code , mais c'est un syndrome connu .
basiquement les valeurs "utiles" MIDI vont de 0 à 127
pour l'acquisition d'un potentiometre sur un arduino basique, la valeur acquises evoluent entre 0 et 1023
il faut gerer les variations d'acquisition brutes sur chaque "pot" pour filtrer/faire de l'hysteresis
J'ai qq prog (multiples POT--->MIDI pour utilisation sous TRAKTOR ) sous le coude ,mais pas avant qq jours

J'ai modifié le programme avec une autre méthode qu'on m'a conseillé

Les potentiomètres se paramètres tres bien dans le DAW
Le problème est que uniquement le potentiomètre de la sortie A6 fonctionne correctement
les autres varient rapidement et leur course présente un creu un peu au dessus du minimum et jusqu’à la moitié
En changeant de potentiomètre c'est toujours le potentiomètre connecté sur la sortie A6 qui fonctionne

J'ai donc retiré le code des boutons 1 par 1 et il se trouve que les potentiomètres fonctionnent mal a partir de l’intégration du code du 4 iemes boutons

En retirant complétement la partie concernant les boutons les 6 potentiomètres fonctionnement

En quoi le code des 5 autres boutons influence t'il les fonctionnement des potentiomètres ?
Est ce que cela viendrai de l'affectation Midi (CC et ch)?

#include <MIDI.h>  // INlcude MIDI library

const int buttonPin = 2;  // the number of the Button pin
const int buttonPin2 = 3;
const int buttonPin3 = 4; 
const int buttonPin4 = 5;
const int buttonPin5 = 6; 
const int buttonPin6 = 7;
const int buttonPin7 = 8; 
const int buttonPin8 = 9;

// the number of the pushbutton pin
const int ledPin =  11;      // the number of the LED pin
const int ledPin2 =  12;
const int ledPin3 =  13;     
const int ledPin4 =  14;
const int ledPin5 =  15;    
const int ledPin6 =  16;
const int ledPin7 =  17;     
const int ledPin8 =  18;
// variables will change:

boolean currentState = LOW;//stroage for current button state
boolean lastState = LOW;//storage for last button state
boolean currentState2 = LOW;
boolean lastState2 = LOW;
boolean currentState3 = LOW;
boolean lastState3 = LOW;
boolean currentState4 = LOW;
boolean lastState4 = LOW;

boolean currentState5 = LOW;
boolean lastState5 = LOW;
boolean currentState6 = LOW;
boolean lastState6 = LOW;
boolean currentState7 = LOW;
boolean lastState7 = LOW;
boolean currentState8 = LOW;
boolean lastState8 = LOW;

void setup()

{
  
  Serial.begin(9600);  // default midi speed rate
   
 pinMode(ledPin, OUTPUT);     // initialize the LED pin as an output:  
  pinMode(buttonPin, INPUT_PULLUP); // initialize the pushbutton pin as an input:
  
pinMode(ledPin2, OUTPUT);      
  pinMode(buttonPin2, INPUT_PULLUP);
  
pinMode(ledPin3, OUTPUT);      
  pinMode(buttonPin3,INPUT_PULLUP); 
  
pinMode(ledPin4, OUTPUT);      
  pinMode(buttonPin4, INPUT_PULLUP);  
  
pinMode(ledPin5, OUTPUT);      
  pinMode(buttonPin5, INPUT_PULLUP); 
 
  pinMode(ledPin6, OUTPUT);      
  pinMode(buttonPin6, INPUT_PULLUP); 
  
  pinMode(ledPin7, OUTPUT);      
  pinMode(buttonPin7,INPUT_PULLUP); 
  
  pinMode(ledPin8, OUTPUT);      
  pinMode(buttonPin8, INPUT_PULLUP);  
 
 MIDI.begin(); 
}
 
static int iAn0Val, iAn1Val, iAn2Val, iAn3Val, iAn4Val, iAn5Val;
 
void loop()
{
    // read the state of the pushbutton value:
    currentState = digitalRead(buttonPin);
    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (currentState == LOW && lastState == HIGH) 
    { 
    digitalWrite(ledPin,HIGH); 
    MIDI.sendNoteOff(42,0,2);// turn LED off  
    } 
    else if (currentState == HIGH && lastState == LOW) 
    { 
    digitalWrite(ledPin, LOW); 
    MIDI.sendNoteOn(42,127,2);// turn LED on
    delay(20);
    MIDI.sendNoteOff(42,0,2); // turn LED off 
    }
    lastState = currentState;            
  
currentState2 = digitalRead(buttonPin2);
     if (currentState2 == LOW && lastState2 == HIGH) 
     {
     digitalWrite(ledPin2,HIGH);  
     MIDI.sendNoteOff(39,0,2);
     } 
     else if (currentState2 == HIGH && lastState2 == LOW) 
     {
     digitalWrite(ledPin2, LOW); 
     MIDI.sendNoteOn(39,127,2);
     delay(20);
     MIDI.sendNoteOff(39,0,2);
     }  
     lastState2 = currentState2;      
  
currentState3 = digitalRead(buttonPin3);
     if (currentState3 == LOW && lastState3 == HIGH) 
     {
     digitalWrite(ledPin3,HIGH);  
     MIDI.sendNoteOff(40,0,2);
     } 
     else if (currentState3 == HIGH && lastState3 == LOW) 
     {
     digitalWrite(ledPin3, LOW); 
     MIDI.sendNoteOn(40,127,2);
     delay(20);
     MIDI.sendNoteOff(40,0,2);
     }  
     lastState3 = currentState3;
     
currentState4 = digitalRead(buttonPin4);
     if (currentState4 == LOW && lastState4 == HIGH) 
     {
     digitalWrite(ledPin4,HIGH);  
     MIDI.sendNoteOff(41,0,2);
     } 
     else if (currentState4 == HIGH && lastState4 == LOW) 
     {
     digitalWrite(ledPin4, LOW); 
     MIDI.sendNoteOn(41,127,2);
     delay(20);
     MIDI.sendNoteOff(41,0,2);
     }  
     lastState4 = currentState4;
     
currentState5 = digitalRead(buttonPin5);
     if (currentState5 == LOW && lastState5 == HIGH) 
     {
     digitalWrite(ledPin5,HIGH);  
     MIDI.sendNoteOff(38,0,2);
     } 
     else if (currentState5 == HIGH && lastState5 == LOW) 
     {
     digitalWrite(ledPin5, LOW); 
     MIDI.sendNoteOn(38,127,2);
     delay(20);
     MIDI.sendNoteOff(38,0,2);
     }  
     lastState5 = currentState5;
     
currentState6 = digitalRead(buttonPin6);
     if (currentState6 == LOW && lastState6 == HIGH) 
     {
     digitalWrite(ledPin6,HIGH);  
     MIDI.sendNoteOff(43,0,2);
     } 
     else if (currentState6 == HIGH && lastState6 == LOW) 
     {
     digitalWrite(ledPin6, LOW); 
     MIDI.sendNoteOn(43,127,2);
     delay(10);
     MIDI.sendNoteOff(43,0,2);
     }  
     lastState6 = currentState6;
     
currentState7 = digitalRead(buttonPin7);
if (currentState7 == LOW && lastState7 == HIGH) 
     {
     digitalWrite(ledPin7,HIGH);  
     MIDI.sendNoteOff(37,0,2);
     } 
     else if (currentState7 == HIGH && lastState7 == LOW) 
     {
     digitalWrite(ledPin7, LOW); 
     MIDI.sendNoteOn(37,127,2);
     delay(10);
     MIDI.sendNoteOff(37,0,2);
     }  
     lastState7 = currentState7;
     
currentState8 = digitalRead(buttonPin8);
if (currentState8 == LOW && lastState8 == HIGH) 
       {
       digitalWrite(ledPin8,HIGH);  
       MIDI.sendNoteOff(44,0,2);
       } 
       else if (currentState8 == HIGH && lastState8 == LOW) 
       {
       digitalWrite(ledPin8, LOW); 
       MIDI.sendNoteOn(44,127,2);
       delay(10);
       MIDI.sendNoteOff(44,0,2);
       }  
       lastState8 = currentState8;

//Pot 01   
   static int iAn0ValPrev;
   iAn0ValPrev = 0 ;
   iAn0ValPrev = iAn0Val ; // previous value
   iAn0Val = analogRead(A0); // Divide by 8 to get range of 0-127 for midi
   if (abs (iAn0Val - iAn0ValPrev)>3)
   analogPinMidiTX(1,iAn0Val,iAn0ValPrev); //TX value 
   delay(10);
//Pot 02
   static int iAn1ValPrev;
   iAn1ValPrev = 0 ;
   iAn1ValPrev = iAn1Val; 
   iAn1Val = analogRead(A1);
   if (abs (iAn1Val - iAn1ValPrev)>3)
   analogPinMidiTX(2,iAn1Val,iAn1ValPrev); 
   delay(10);
//Pot 03 
   static int iAn2ValPrev;
   iAn2ValPrev = 0 ;
   iAn2ValPrev = iAn2Val; 
   iAn2Val = analogRead(A2);
   if (abs (iAn2Val - iAn2ValPrev)>3)
   analogPinMidiTX(3,iAn2Val,iAn2ValPrev);
   delay(10);
//Pot 04
   static int iAn3ValPrev;
   iAn3ValPrev = 0; 
   iAn3ValPrev = iAn3Val; 
   iAn3Val = analogRead(A3);
   if (abs (iAn3Val - iAn3ValPrev)>3)
   analogPinMidiTX(4,iAn3Val,iAn3ValPrev); 
   delay(10);
//Pot 05
   static int iAn4ValPrev;
   iAn4ValPrev = 0;
   iAn4ValPrev = iAn4Val; 
   iAn4Val = analogRead(A4);
   if (abs (iAn4Val - iAn4ValPrev)>3)
   analogPinMidiTX(5,iAn4Val,iAn4ValPrev);
   delay(10);
   //Pot 06
   static int iAn5ValPrev;
   iAn5ValPrev = 0;
   iAn5ValPrev = iAn5Val; 
   iAn5Val = analogRead(A5);
   if (abs (iAn5Val - iAn5ValPrev)>3)
   analogPinMidiTX(6,iAn5Val,iAn5ValPrev);
   delay(10); //here we add a short delay to help prevent slight fluctuations, knocks on the pots etc. Adding this helped to prevent my pots from jumpin up or down a value when slightly touched or knocked.
}

void analogPinMidiTX(int iChan, int iVal, int iValPrev)
{  
  // TX Value only if it has changed
  if(iValPrev != iVal)
  {
    iValPrev != iVal ;
    iVal = iVal >> 3 ;
    MidiTX(176,iChan,iVal); // 176 = CC command, 1 = Which Control, val = value read from Potentionmeter
     
   }
}

void MidiTX(unsigned char MESSAGE, unsigned char CONTROL, unsigned char VALUE) //Valeur en Midi Command
{
   Serial.write(MESSAGE);
   Serial.write(CONTROL);
   Serial.write(VALUE);
}