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);
}