Voici les progrès effectués, je ne sais pas si c'est la meilleure façon de faire, mais "ça marche à peu près".
// Constantes d'entrées :
const int CH1 = A1; // Bouton de contrôle du canal 1
const int CH2 = A2; // Bouton de contrôle du canal 2
const int CH3 = A3; // Bouton de contrôle du canal 3
const int CH4 = A4; // Bouton de contrôle du canal 4
const int CH5 = A5; // Bouton de contrôle du canal 5
const int CH6 = A6; // Bouton de contrôle du canal 6
const int MST = A7; // Bouton de contrôle du canal Master
// Constantes de sorties :
const int CH1_FX1= 0; // Sortie pour router le canal 1 sur le bus FX1
const int CH1_FX2= 1; // Sortie pour router le canal 1 sur le bus FX2
const int CH2_FX1= 2; // Sortie pour router le canal 2 sur le bus FX1
const int CH2_FX2= 3; // Sortie pour router le canal 2 sur le bus FX2
const int CH3_FX1= 4; // Sortie pour router le canal 3 sur le bus FX1
const int CH3_FX2= 5; // Sortie pour router le canal 3 sur le bus FX2
const int CH4_FX1= 6; // Sortie pour router le canal 4 sur le bus FX1
const int CH4_FX2= 7; // Sortie pour router le canal 4 sur le bus FX2
const int CH5_FX1= 8; // Sortie pour router le canal 5 sur le bus FX1
const int CH5_FX2= 9; // Sortie pour router le canal 5 sur le bus FX2
const int CH6_FX1= 10; // Sortie pour router le canal 6 sur le bus FX1
const int CH6_FX2= 11; // Sortie pour router le canal 6 sur le bus FX2
const int MST_FX1= 12; // Sortie pour router le canal Master sur le bus FX1
const int MST_FX2= 13; // Sortie pour router le canal Master sur le bus FX1
// Définition des variables :
int CH1_State = 0; // Variable CH1
int CH1_FX1_state = LOW; // the current state of the output pin
int CH1_FX1_reading; // the current reading from the input pin
int CH1_FX1_previous = HIGH; // the previous reading from the input pin
int CH1_FX2_state = LOW; // the current state of the output pin
int CH1_FX2_reading; // the current reading from the input pin
int CH1_FX2_previous = HIGH; // the previous reading from the input pin
int CH2_State = 0; // Variable CH2
int CH2_FX1_state = LOW; // the current state of the output pin
int CH2_FX1_reading; // the current reading from the input pin
int CH2_FX1_previous = HIGH; // the previous reading from the input pin
int CH2_FX2_state = LOW; // the current state of the output pin
int CH2_FX2_reading; // the current reading from the input pin
int CH2_FX2_previous = HIGH; // the previous reading from the input pin
int CH3_State = 0; // Variable CH3
int CH3_FX1_state = LOW; // the current state of the output pin
int CH3_FX1_reading; // the current reading from the input pin
int CH3_FX1_previous = HIGH; // the previous reading from the input pin
int CH3_FX2_state = LOW; // the current state of the output pin
int CH3_FX2_reading; // the current reading from the input pin
int CH3_FX2_previous = HIGH; // the previous reading from the input pin
int CH4_State = 0; // Variable CH4
int CH4_FX1_state = LOW; // the current state of the output pin
int CH4_FX1_reading; // the current reading from the input pin
int CH4_FX1_previous = HIGH; // the previous reading from the input pin
int CH4_FX2_state = LOW; // the current state of the output pin
int CH4_FX2_reading; // the current reading from the input pin
int CH4_FX2_previous = HIGH; // the previous reading from the input pin
int CH5_State = 0; // Variable CH5
int CH5_FX1_state = LOW; // the current state of the output pin
int CH5_FX1_reading; // the current reading from the input pin
int CH5_FX1_previous = HIGH; // the previous reading from the input pin
int CH5_FX2_state = LOW; // the current state of the output pin
int CH5_FX2_reading; // the current reading from the input pin
int CH5_FX2_previous = HIGH; // the previous reading from the input pin
int CH6_State = 0; // Variable CH6
int CH6_FX1_state = LOW; // the current state of the output pin
int CH6_FX1_reading; // the current reading from the input pin
int CH6_FX1_previous = HIGH; // the previous reading from the input pin
int CH6_FX2_state = LOW; // the current state of the output pin
int CH6_FX2_reading; // the current reading from the input pin
int CH6_FX2_previous = HIGH; // the previous reading from the input pin
int MST_State = 0; // Variable Master
int MST_FX1_state = LOW; // the current state of the output pin
int MST_FX1_reading; // the current reading from the input pin
int MST_FX1_previous = HIGH; // the previous reading from the input pin
int MST_FX2_state = LOW; // the current state of the output pin
int MST_FX2_reading; // the current reading from the input pin
int MST_FX2_previous = HIGH; // the previous reading from the input pin
// Réglage de la sensibilité des boutons :
int I0V = 587; // Input 0V : Limite haute de l'information 0V
int I3VL = 637; // Input 3V Low : limite basse de l'information 3.3V
int I3VH = 737; // Input 3V High : limite haute de l'information 3.3V
int I5VL = 973; // Input 5V Low : limite basse de l'information 5V
int I5VH = 1073; // Input 5V High : limite haute de l'information 5V
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup() {
// Activation du port série afin de tester les entrées analogiques
// Serial.begin(9600);
// Initialisation des entrées :
pinMode(CH1, INPUT);
pinMode(CH2, INPUT);
pinMode(CH3, INPUT);
pinMode(CH4, INPUT);
pinMode(CH5, INPUT);
pinMode(CH6, INPUT);
pinMode(MST, INPUT);
// Initialisation des sorties :
pinMode(CH1_FX1, OUTPUT);
pinMode(CH1_FX2, OUTPUT);
pinMode(CH2_FX1, OUTPUT);
pinMode(CH2_FX2, OUTPUT);
pinMode(CH3_FX1, OUTPUT);
pinMode(CH3_FX2, OUTPUT);
pinMode(CH4_FX1, OUTPUT);
pinMode(CH4_FX2, OUTPUT);
pinMode(CH5_FX1, OUTPUT);
pinMode(CH5_FX2, OUTPUT);
pinMode(CH6_FX1, OUTPUT);
pinMode(CH6_FX2, OUTPUT);
pinMode(MST_FX1, OUTPUT);
pinMode(MST_FX2, OUTPUT);
}
void loop() {
// Test de la lecture analogique du bouton :
int sensorValue = analogRead(CH3);
float voltage = sensorValue * (5.0 / 1023.0);
float value = sensorValue;
Serial.println(value);
// Lecture de l'état des entrées :
CH1_State = analogRead(CH1);
CH2_State = analogRead(CH2);
CH3_State = analogRead(CH3);
CH4_State = analogRead(CH4);
CH5_State = analogRead(CH5);
CH6_State = analogRead(CH6);
MST_State = analogRead(MST);
// Channel 1 :
if (CH1_State > I3VL && CH1_State < I3VH && CH1_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 3.3V ET que l'état précédent était à LOW ET que le temps anti rebond est passé :
{if (CH1_FX1_state == HIGH)CH1_FX1_state = LOW;
else CH1_FX1_state = HIGH;
time = millis();}
{digitalWrite(CH1_FX1, CH1_FX1_state);
CH1_FX1_previous = CH1_FX1_reading;}
if (CH1_State > I5VL && CH1_State < I5VH && CH1_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 5V :
{if (CH1_FX2_state == HIGH)CH1_FX2_state = LOW;
else CH1_FX2_state = HIGH; time = millis();}
{digitalWrite(CH1_FX2, CH1_FX2_state);
CH1_FX2_previous = CH1_FX2_reading;}
// Channel 2 :
if (CH2_State > I3VL && CH2_State < I3VH && CH2_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 3.3V ET que l'état précédent était à LOW ET que le temps anti rebond est passé :
{if (CH2_FX1_state == HIGH)CH2_FX1_state = LOW;
else CH2_FX1_state = HIGH;
time = millis();}
{digitalWrite(CH2_FX1, CH2_FX1_state);
CH2_FX1_previous = CH2_FX1_reading;}
if (CH2_State > I5VL && CH2_State < I5VH && CH2_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 5V :
{if (CH2_FX2_state == HIGH)CH2_FX2_state = LOW;
else CH2_FX2_state = HIGH; time = millis();}
{digitalWrite(CH2_FX2, CH2_FX2_state);
CH2_FX2_previous = CH2_FX2_reading;}
// Channel 3 :
if (CH3_State > I3VL && CH3_State < I3VH && CH3_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 3.3V :
{if (CH3_FX1_state == HIGH)CH3_FX1_state = LOW;
else CH3_FX1_state = HIGH;
time = millis();}
{digitalWrite(CH3_FX1, CH3_FX1_state);
CH3_FX1_previous = CH3_FX1_reading;}
if (CH3_State > I5VL && CH3_State < I5VH && CH3_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 5V :
{if (CH3_FX2_state == HIGH)CH3_FX2_state = LOW;
else CH3_FX2_state = HIGH; time = millis();}
{digitalWrite(CH3_FX2, CH3_FX2_state);
CH3_FX2_previous = CH3_FX2_reading;}
// Channel 4 :
if (CH4_State > I3VL && CH4_State < I3VH && CH4_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 3.3V :
{if (CH4_FX1_state == HIGH)CH4_FX1_state = LOW;
else CH4_FX1_state = HIGH;
time = millis();}
{digitalWrite(CH4_FX1, CH4_FX1_state);
CH4_FX1_previous = CH4_FX1_reading;}
if (CH4_State > I5VL && CH4_State < I5VH && CH4_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 5V :
{if (CH4_FX2_state == HIGH)CH4_FX2_state = LOW;
else CH4_FX2_state = HIGH; time = millis();}
{digitalWrite(CH4_FX2, CH4_FX2_state);
CH4_FX2_previous = CH4_FX2_reading;}
// Channel 5 :
if (CH5_State > I3VL && CH5_State < I3VH && CH5_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 3.3V :
{if (CH5_FX1_state == HIGH)CH5_FX1_state = LOW;
else CH5_FX1_state = HIGH;
time = millis();}
{digitalWrite(CH5_FX1, CH5_FX1_state);
CH5_FX1_previous = CH5_FX1_reading;}
if (CH5_State > I5VL && CH5_State < I5VH && CH5_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 5V :
{if (CH5_FX2_state == HIGH)CH5_FX2_state = LOW;
else CH5_FX2_state = HIGH; time = millis();}
{digitalWrite(CH5_FX2, CH5_FX2_state);
CH5_FX2_previous = CH5_FX2_reading;}
// Channel 6 :
if (CH6_State > I3VL && CH6_State < I3VH && CH6_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 3.3V :
{if (CH6_FX1_state == HIGH)CH6_FX1_state = LOW;
else CH6_FX1_state = HIGH;
time = millis();}
{digitalWrite(CH6_FX1, CH6_FX1_state);
CH6_FX1_previous = CH6_FX1_reading;}
if (CH6_State > I5VL && CH6_State < I5VH && CH6_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 5V :
{if (CH6_FX2_state == HIGH)CH6_FX2_state = LOW;
else CH6_FX2_state = HIGH; time = millis();}
{digitalWrite(CH6_FX2, CH6_FX2_state);
CH6_FX2_previous = CH6_FX2_reading;}
// Master :
if (MST_State > I3VL && MST_State < I3VH && MST_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 3.3V :
{if (MST_FX1_state == HIGH)MST_FX1_state = LOW;
else MST_FX1_state = HIGH;
time = millis();}
{digitalWrite(MST_FX1, MST_FX1_state);
MST_FX1_previous = MST_FX1_reading;}
if (MST_State > I5VL && MST_State < I5VH && MST_FX1_previous == LOW && millis() - time > debounce) // Si l'entrée est à 5V :
{if (MST_FX2_state == HIGH)MST_FX2_state = LOW;
else MST_FX2_state = HIGH; time = millis();}
{digitalWrite(MST_FX2, MST_FX2_state);
MST_FX2_previous = MST_FX2_reading;}
// Marqueur de fin de programme
}
Est ce que vous pourriez me dire comment je devrais m'y prendre pour que quand par exemple FX1 est activé et que j'active FX2, FX1 soit coupé, et vice versa ?
J'ai gratté un peu partout toute la soirée, sans trouver d'information probante.
Merci d'avance !
Jérôme.