update I2C adresse
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"stm32-for-vscode.openOCDPath": false,
|
||||
"stm32-for-vscode.armToolchainPath": false
|
||||
}
|
||||
@@ -22,39 +22,57 @@ void button_position_save() // calcul de la différence entre gain et volume
|
||||
{
|
||||
if (const_out_L_state == true) // si bouton const_out_L appuyé
|
||||
{
|
||||
Serial.println("========== memory position =========");
|
||||
for (int i = 0; i <= 1; i++)
|
||||
{
|
||||
moteur_stop(i); // arrêt des moteurs
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_memory[i] = position_lue[i];
|
||||
Serial.print("position_memory[");
|
||||
Serial.print(i);
|
||||
Serial.print("] = ");
|
||||
Serial.println(position_memory[i]);
|
||||
}
|
||||
Serial.println("===================================");
|
||||
}
|
||||
|
||||
if (const_out_R_state == true) // si bouton const_out_R appuyé
|
||||
{
|
||||
Serial.println("========== memory position =========");
|
||||
for (int i = 2; i <= 3; i++)
|
||||
{
|
||||
moteur_stop(i); // arrêt des moteurs
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_memory[i] = position_lue[i];
|
||||
Serial.print("position_memory[");
|
||||
Serial.print(i);
|
||||
Serial.print("] = ");
|
||||
Serial.println(position_memory[i]);
|
||||
}
|
||||
Serial.println("===================================");
|
||||
}
|
||||
|
||||
if (stereo_link_state == true) // si bouton stereo_link appuyé
|
||||
{
|
||||
Serial.println("========== memory position =========");
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
moteur_stop(i); // arrêt des moteurs
|
||||
moteur_stop(i); // arrêt des moteurs
|
||||
lecture_pot(i); // lecture des potentiomètres
|
||||
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
|
||||
position_memory[i] = position_lue[i];
|
||||
Serial.print("position_memory[");
|
||||
Serial.print(i);
|
||||
Serial.print("] = ");
|
||||
Serial.println(position_memory[i]);
|
||||
}
|
||||
Serial.println("===================================");
|
||||
}
|
||||
}
|
||||
|
||||
void lecture_switch()
|
||||
void lecture_switch() // lecture des boutons
|
||||
{
|
||||
// lecture des boutons
|
||||
stereo_link.update();
|
||||
@@ -75,7 +93,7 @@ void lecture_switch()
|
||||
}
|
||||
}
|
||||
|
||||
void bouton_set()
|
||||
void bouton_set() // gestion des boutons
|
||||
{
|
||||
lecture_switch();
|
||||
if (stereo_link_state_old != stereo_link_state) // si changement d'état du bouton stereo_link
|
||||
@@ -112,6 +130,8 @@ void stereo_link_set() // gestion du bouton stereo_link
|
||||
else // si bouton stereo_link relaché
|
||||
{
|
||||
digitalWrite(stereo_link_led, LOW); // éteint LED stereo_link
|
||||
const_out_R_state_old = const_out_R_state;
|
||||
const_out_L_state_old = const_out_L_state;
|
||||
// sécurité d'arrêt des moteurs
|
||||
for (int i = 0; i <= 3; i++) // pour chaque moteur
|
||||
{
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
/*******************************************************************************************************
|
||||
Gestion de la calibration des min et max des potentiomètres et stockage dans l'EEPROM
|
||||
********************************************************************************************************/
|
||||
#include <EEPROM.h>
|
||||
|
||||
#define speed 20
|
||||
#define interval_cal 3000
|
||||
#define largeur_addr 5
|
||||
#define nb_addr 4
|
||||
|
||||
void calibration_pot(int i); // definition fonction de calibration des potentiomètres
|
||||
|
||||
void calibration_pot(int i) // calibration des potentiomètres
|
||||
{
|
||||
int value;
|
||||
int map_value;
|
||||
int eeprom_value;
|
||||
|
||||
if (analogRead(analog_pot[i]) > 800)
|
||||
{
|
||||
motor[i].drive(63);
|
||||
@@ -19,9 +27,56 @@ void calibration_pot(int i) // calibration des potentiomètres
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// *******************************************************************************************************
|
||||
// calibration du max des potentiomètres
|
||||
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
|
||||
while (analogRead(analog_pot[i]) > 50) // en analogue read les valeurs sont inversées
|
||||
{
|
||||
delay(200);
|
||||
digitalWrite(const_out_L_led, LOW);
|
||||
digitalWrite(const_out_R_led, HIGH);
|
||||
motor[i].drive(63);
|
||||
delay(200);
|
||||
digitalWrite(const_out_L_led, HIGH);
|
||||
digitalWrite(const_out_R_led, LOW);
|
||||
}
|
||||
motor[i].drive(speed);
|
||||
delay(interval_cal);
|
||||
motor[i].stop();
|
||||
|
||||
delay(500);
|
||||
digitalWrite(stereo_link_led, LOW); // éteint LED stereo_link
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
gain_0.update();
|
||||
value = gain_0.getValue();
|
||||
break;
|
||||
case 1:
|
||||
vol_0.update();
|
||||
value = vol_0.getValue();
|
||||
break;
|
||||
case 2:
|
||||
gain_1.update();
|
||||
value = gain_1.getValue();
|
||||
break;
|
||||
case 3:
|
||||
vol_1.update();
|
||||
value = vol_1.getValue();
|
||||
break;
|
||||
}
|
||||
map_value = map(value, max_pot[i], value, 0, 1023);
|
||||
eeprom_value = constrain(map_value, 0, 1023);
|
||||
max_pot[i] = eeprom_value;
|
||||
EEPROM.put((i * largeur_addr), max_pot[i]);
|
||||
delay(500);
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
// *******************************************************************************************************
|
||||
// calibration du min des potentiomètres
|
||||
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
|
||||
digitalWrite(stereo_link_led, HIGH); // éteint LED stereo_link
|
||||
|
||||
while (analogRead(analog_pot[i]) < 950) // en analogue read les valeurs sont inversées
|
||||
{
|
||||
delay(200);
|
||||
@@ -41,68 +96,33 @@ void calibration_pot(int i) // calibration des potentiomètres
|
||||
{
|
||||
case 0:
|
||||
gain_0.update();
|
||||
max_pot[i] = gain_0.getValue();
|
||||
value = gain_0.getValue();
|
||||
break;
|
||||
case 1:
|
||||
vol_0.update();
|
||||
max_pot[i] = vol_0.getValue();
|
||||
value = vol_0.getValue();
|
||||
break;
|
||||
case 2:
|
||||
gain_1.update();
|
||||
max_pot[i] = gain_1.getValue();
|
||||
value = gain_1.getValue();
|
||||
break;
|
||||
case 3:
|
||||
vol_1.update();
|
||||
max_pot[i] = vol_1.getValue();
|
||||
value = vol_1.getValue();
|
||||
break;
|
||||
}
|
||||
EEPROM.write(i + 10, max_pot[i] / 4);
|
||||
map_value = map(value, value, min_pot[i], 0, 1023);
|
||||
eeprom_value = constrain(map_value, 0, 1023);
|
||||
max_pot[i] = eeprom_value;
|
||||
EEPROM.put(((largeur_addr * nb_addr) + (i * largeur_addr)), max_pot[i]);
|
||||
delay(500);
|
||||
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
// *******************************************************************************************************
|
||||
// calibration du max des potentiomètres
|
||||
digitalWrite(stereo_link_led, HIGH); // éteint LED stereo_link
|
||||
while (analogRead(analog_pot[i]) > 50) // en analogue read les valeurs sont inversées
|
||||
{
|
||||
delay(200);
|
||||
digitalWrite(const_out_L_led, LOW);
|
||||
digitalWrite(const_out_R_led, HIGH);
|
||||
motor[i].drive(63);
|
||||
delay(200);
|
||||
digitalWrite(const_out_L_led, HIGH);
|
||||
digitalWrite(const_out_R_led, LOW);
|
||||
}
|
||||
motor[i].drive(speed);
|
||||
delay(interval_cal);
|
||||
motor[i].stop();
|
||||
delay(500);
|
||||
digitalWrite(stereo_link_led, LOW); // éteint LED stereo_link
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
gain_0.update();
|
||||
min_pot[i] = gain_0.getValue();
|
||||
break;
|
||||
case 1:
|
||||
vol_0.update();
|
||||
min_pot[i] = vol_0.getValue();
|
||||
break;
|
||||
case 2:
|
||||
gain_1.update();
|
||||
min_pot[i] = gain_1.getValue();
|
||||
break;
|
||||
case 3:
|
||||
vol_1.update();
|
||||
min_pot[i] = vol_1.getValue();
|
||||
break;
|
||||
}
|
||||
EEPROM.write(i, min_pot[i] / 4);
|
||||
delay(500);
|
||||
digitalWrite(stereo_link_led, HIGH); // éteint LED stereo_link
|
||||
|
||||
// remise à zéro du potentiomètres
|
||||
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
|
||||
while (analogRead(analog_pot[i]) < max_pot[i]) // en analogue read les valeurs sont inversées
|
||||
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
|
||||
while (analogRead(analog_pot[i]) < max_pot[i] - 50) // en analogue read les valeurs sont inversées
|
||||
{
|
||||
delay(200);
|
||||
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
|
||||
|
||||
@@ -2,23 +2,25 @@
|
||||
gestion des consigne et des calcul de position des moteurs
|
||||
*******************************************************************************************************/
|
||||
|
||||
void consigne_set(int i); // calcul des consignes
|
||||
void motor_calc(int pot, int motor); // calcul des position de moteurs
|
||||
void position_const_calc(int pot, int motor); // calcul de la consigne de position
|
||||
void position_stereo_calc(int pot, int motor); // calcul de la consigne de position en stereo
|
||||
void motor_calc(int pot, int motor); // calcul des position de moteurs
|
||||
void position_stereo_calc(int pot, int motor); // calcul de la consigne de position en stereo
|
||||
void position_stereo_const_calc(int pot, int motor); // calcul de la consigne de position en stereo et constant output
|
||||
void position_const_calc(int pot, int motor); // calcul de la consigne de position en constant output
|
||||
void consigne_set(int i); // calcul des consignes
|
||||
|
||||
void motor_calc(int pot, int motor) // calcul des consignes de moteurs et du flag de changement de position
|
||||
{
|
||||
lecture_pot(pot); // lecture des potentiomètres
|
||||
lecture_pot(motor); // lecture des potentiomètres
|
||||
if (position_set[motor] <= 0)
|
||||
// calcul de la consigne de position des moteurs en min et max
|
||||
if (position_set[motor] < min_val_pot)
|
||||
{
|
||||
position_set[motor] = min_pot[motor];
|
||||
position_set[motor] = min_val_pot;
|
||||
}
|
||||
else if (position_set[motor] >= 1023)
|
||||
else if (position_set[motor] > max_val_pot)
|
||||
{
|
||||
position_set[motor] = max_pot[motor];
|
||||
position_set[motor] = max_val_pot;
|
||||
}
|
||||
// calcul du flag de changement de position du potentiomètre
|
||||
if (position_lue[motor] <= (position_set[motor] + ECART_V_STOP) && position_lue[motor] >= (position_set[motor] - ECART_V_STOP)) // si moteur entre consigne et ECART_V_STOP
|
||||
{
|
||||
motor_change[motor] = false; // moteur entre consigne et ECART_V_STOP
|
||||
@@ -29,6 +31,42 @@ void motor_calc(int pot, int motor) // calcul des consignes de moteurs et du fla
|
||||
}
|
||||
}
|
||||
|
||||
void position_stereo_calc(int pot, int motor)
|
||||
{
|
||||
if (position_lue[pot] < position_memory[pot] - ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] - (position_memory[pot] - position_lue[pot]);
|
||||
motor_calc(pot, motor);
|
||||
}
|
||||
else if (position_lue[pot] > position_memory[pot] + ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] + (position_lue[pot] - position_memory[pot]);
|
||||
motor_calc(pot, motor);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void position_stereo_const_calc(int pot, int motor)
|
||||
{
|
||||
if (position_set[pot] < position_memory[pot] - ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] + (position_memory[pot] - position_set[pot]);
|
||||
motor_calc(pot, motor);
|
||||
}
|
||||
else if (position_set[pot] > position_memory[pot] + ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] - (position_set[pot] - position_memory[pot]);
|
||||
motor_calc(pot, motor);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void position_const_calc(int pot, int motor)
|
||||
{
|
||||
if (position_lue[pot] < position_memory[pot] - ECART_V_STOP)
|
||||
@@ -47,43 +85,6 @@ void position_const_calc(int pot, int motor)
|
||||
}
|
||||
}
|
||||
|
||||
void position_stereo_const_calc(int pot, int motor)
|
||||
{
|
||||
if (position_set[pot] < position_memory[pot] - ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] + (position_memory[pot] - position_set[pot]);
|
||||
motor_calc(pot, motor); // pot, motor
|
||||
}
|
||||
else if (position_set[pot] > position_memory[pot] + ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] - (position_set[pot] - position_memory[pot]);
|
||||
motor_calc(pot, motor); // pot, motor
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void position_stereo_calc(int pot, int motor)
|
||||
{
|
||||
if (position_lue[pot] < position_memory[pot] - ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] - (position_memory[pot] - position_lue[pot]);
|
||||
motor_calc(pot, motor); // pot, motor
|
||||
}
|
||||
else if (position_lue[pot] > position_memory[pot] + ECART_V_STOP)
|
||||
{
|
||||
position_set[motor] = position_memory[motor] + (position_lue[pot] - position_memory[pot]);
|
||||
|
||||
motor_calc(pot, motor); // pot, motor
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void consigne_set(int i) // calcul des consignes de moteurs
|
||||
{
|
||||
if (stereo_link_state == true) // si stereo_link actif
|
||||
@@ -91,81 +92,91 @@ void consigne_set(int i) // calcul des consignes de moteurs
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
position_stereo_calc(0, 2); // pot, motor
|
||||
position_stereo_calc(0, 2);
|
||||
if (const_out_L_state == true || const_out_R_state == true)
|
||||
{
|
||||
position_const_calc(0, 1);
|
||||
position_stereo_const_calc(2, 3);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
position_stereo_calc(1, 3); // pot, motor
|
||||
position_stereo_calc(1, 3);
|
||||
if (const_out_L_state == true || const_out_R_state == true)
|
||||
{
|
||||
position_const_calc(1, 0);
|
||||
position_stereo_const_calc(3, 2);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
position_stereo_calc(2, 0); // pot, motor
|
||||
if (const_out_L_state == true || const_out_R_state == true)
|
||||
{
|
||||
position_const_calc(2, 3);
|
||||
position_stereo_const_calc(0, 1);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
position_stereo_calc(3, 1); // pot, motor
|
||||
if (const_out_L_state == true || const_out_R_state == true)
|
||||
{
|
||||
position_const_calc(3, 2);
|
||||
position_stereo_const_calc(1, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (const_out_L_state == true) // si bouton const_out_L ou R appuyé
|
||||
else if (const_out_L_state == true) // si uniquement const_out_L actif
|
||||
{
|
||||
const int gain_const = 0;
|
||||
const int volume_const = 1;
|
||||
const int gain_norm = 2;
|
||||
const int volume_norm = 3;
|
||||
switch (i)
|
||||
{
|
||||
case gain_const:
|
||||
position_const_calc(gain_const, volume_const);
|
||||
if (stereo_link_state == true)
|
||||
{
|
||||
position_stereo_const_calc(gain_norm, volume_norm);
|
||||
}
|
||||
break;
|
||||
case volume_const:
|
||||
position_const_calc(volume_const, gain_const);
|
||||
if (stereo_link_state == true)
|
||||
{
|
||||
position_stereo_const_calc(volume_norm, gain_norm);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (stereo_link_state != true)
|
||||
position_set[i] = position_lue[i];
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (const_out_R_state == true) // si const_out_L actif
|
||||
else if (const_out_R_state == true) // si uniquement const_out_L actif
|
||||
{
|
||||
const int gain_const = 2;
|
||||
const int volume_const = 3;
|
||||
const int gain_norm = 0;
|
||||
const int volume_norm = 1;
|
||||
switch (i)
|
||||
{
|
||||
case gain_const:
|
||||
position_const_calc(gain_const, volume_const);
|
||||
if (stereo_link_state == true)
|
||||
{
|
||||
position_stereo_const_calc(gain_norm, volume_norm);
|
||||
}
|
||||
break;
|
||||
case volume_const:
|
||||
position_const_calc(volume_const, gain_const);
|
||||
if (stereo_link_state == true)
|
||||
{
|
||||
position_stereo_const_calc(volume_norm, gain_norm);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (stereo_link_state != true)
|
||||
position_set[i] = position_lue[i];
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
Serial.print("position_set[");
|
||||
Serial.print(i);
|
||||
Serial.print("] = ");
|
||||
Serial.println(position_set[i]);
|
||||
Serial.print("position_memory[");
|
||||
Serial.print(i);
|
||||
Serial.print("] = ");
|
||||
Serial.println(position_memory[i]);
|
||||
Serial.print("position_lue[");
|
||||
Serial.print(i);
|
||||
Serial.print("] = ");
|
||||
Serial.println(position_lue[i]);
|
||||
*/
|
||||
}
|
||||
@@ -11,7 +11,6 @@ c.saillant@gmail.com
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ******************** pour activer ou non le DEBUG *****************************************************
|
||||
@@ -56,6 +55,9 @@ void setup()
|
||||
debug_init();
|
||||
#endif
|
||||
|
||||
Serial.begin(115200);
|
||||
analogReference(EXTERNAL); // utilisation de la référence de tension externe
|
||||
|
||||
// set bouton const_out_L
|
||||
pinMode(const_out_sw_L, INPUT_PULLUP);
|
||||
pinMode(const_out_L_led, OUTPUT);
|
||||
@@ -75,6 +77,16 @@ void setup()
|
||||
stereo_link.interval(interval_button);
|
||||
stereo_link.setPressedState(LOW);
|
||||
|
||||
// allumage des leds
|
||||
digitalWrite(stereo_link_led, HIGH);
|
||||
digitalWrite(const_out_L_led, HIGH);
|
||||
digitalWrite(const_out_R_led, HIGH);
|
||||
|
||||
gain_0.enableEdgeSnap();
|
||||
vol_0.enableEdgeSnap();
|
||||
gain_1.enableEdgeSnap();
|
||||
vol_1.enableEdgeSnap();
|
||||
|
||||
// set motor stop
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
@@ -85,6 +97,9 @@ void setup()
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
position_set[i] = position_lue[i];
|
||||
}
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
// calibration des potentiomètres avec bouton stereo_link enfoncé au démarrage
|
||||
if (digitalRead(stereo_link_sw) == LOW)
|
||||
{
|
||||
@@ -97,19 +112,21 @@ void setup()
|
||||
digitalWrite(stereo_link_led, LOW);
|
||||
stereo_link_state = false; // initialisation de l'état du bouton stereo_link en cas de démarrage avec le bouton enfoncé pour la calibration
|
||||
}
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
// lecture des valeurs de calibration enregistrées dans la mémoire EEPROM
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
max_pot[i] = EEPROM.read(i + 10) * 4;
|
||||
if (max_pot[i] == 0)
|
||||
{
|
||||
max_pot[i] = 1023;
|
||||
}
|
||||
min_pot[i] = (EEPROM.read(i) * 4) + 1;
|
||||
// EEPROM.get(((largeur_addr * nb_addr) + (i * largeur_addr)), max_pot[i]);
|
||||
// EEPROM.get((i * largeur_addr), min_pot[i]);
|
||||
}
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
digitalWrite(const_out_L_led, LOW);
|
||||
digitalWrite(const_out_R_led, LOW);
|
||||
digitalWrite(stereo_link_led, LOW);
|
||||
bouton_set(); // lecture et controle des boutons
|
||||
}
|
||||
|
||||
@@ -135,22 +152,26 @@ void loop()
|
||||
lecture_pot(i); // lecture analogique potentiomètre avec mise à jour du flag de changement de potentiomètre
|
||||
if (position_change[i] == true) // si changement de position d'un potentiomètre
|
||||
{
|
||||
if (stereo_link_state != true && const_out_L_state != true && const_out_R_state != true) // si pas de contrôle constant output
|
||||
if (stereo_link_state != true && const_out_L_state != true && const_out_R_state != true && millis() >= last_pot_change[i] + 150) // si pas de contrôle constant output
|
||||
{
|
||||
valeurs_set(i); // controle des valeurs et des relais en mode normal
|
||||
valeurs_set(i); // controle des valeurs et des relais en mode normal
|
||||
motor[i].stop(); // stop moteur
|
||||
motor_change[i] = false;
|
||||
}
|
||||
// si contrôle constant output ou stereo link avec moteur arrêté il y a plus de bounce_time_pot et mouvement supérieur à ECART_V_STOP
|
||||
else if (motor_change[i] != true && millis() > last_motor_end[i] + bounce_time_pot)
|
||||
// si contrôle constant output ou stereo link avec moteur arrêté depuis plus que bounce_time_pot
|
||||
else if (motor_change[i] != true && millis() > last_motor_end + 500)
|
||||
{
|
||||
if (abs(position_lue[i] - position_set[i]) >= ECART_V_STOP)
|
||||
if (abs(position_lue[i] - position_set[i]) > ECART_V_STOP)
|
||||
{
|
||||
position_set[i] = position_lue[i];
|
||||
motor[i].brake();
|
||||
consigne_set(i); // mise à jour des consignes
|
||||
for (int i = 0; i <= 3; i++)
|
||||
{
|
||||
// if (motor_change[i] != true)
|
||||
valeurs_const_set(i); // controle des valeurs et des relais en mode constant output
|
||||
}
|
||||
}
|
||||
position_set[i] = position_lue[i];
|
||||
}
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
}
|
||||
@@ -158,6 +179,10 @@ void loop()
|
||||
{
|
||||
moteur_set(i); // controle du moteurs
|
||||
}
|
||||
else if (motor_change[i] == false)
|
||||
{
|
||||
motor[i].stop(); // stop moteur
|
||||
}
|
||||
}
|
||||
if (error_state == true)
|
||||
{
|
||||
|
||||
@@ -8,44 +8,84 @@ Attempts to set speed lower than 6 will be ignored; speeds higher than 63 will b
|
||||
*/
|
||||
|
||||
MiniMoto motor[4] = {gain_0_motor, vol_0_motor, gain_1_motor, vol_1_motor}; // Create MiniMoto instances, pour controle des moteur en I2C (DRV8830)
|
||||
#define ECART_V_STOP 3 // hystérésie de positionnement potentiomètre
|
||||
#define ECART_V_STOP 2 // hystérésie de positionnement potentiomètre
|
||||
#define ECART_V_SPEED_PID 50 // valeur d'écart pour vitesse moteur avec ou sans PID
|
||||
#define ECART_V_MIN_MAX 10 // valeur d'écart au min et au max pour vitesse moteur
|
||||
#define ECART_V_MIN_MAX 5 // valeur d'écart au min et au max pour vitesse moteur
|
||||
|
||||
#define speed_min 10 // vitesse moteur sans PID
|
||||
#define PID_speed_min 15 // vitesse min moteur avec PID
|
||||
#define PID_speed_min 25 // vitesse min moteur avec PID
|
||||
#define PID_speed_max 63 // vitesse max moteur avec PID
|
||||
|
||||
#include <FastPID.h>
|
||||
float Kp = 0.1, Ki = 0.5, Kd = 0, Hz = 2;
|
||||
#if bit_read_pot == 4 // configuration PID en fonction de la précision de lecture du potentiomètre
|
||||
float Kp = 0.8, Ki = 0.1, Kd = 0.2, Hz = 250; // a regler
|
||||
#elif bit_read_pot == 2
|
||||
float Kp = 0.6, Ki = 0.1, Kd = 0.2, Hz = 250; // a tester
|
||||
#elif bit_read_pot == 1
|
||||
float Kp = 0.6, Ki = 0.1, Kd = 0.2, Hz = 250; // OK
|
||||
#endif
|
||||
|
||||
int output_bits = 8;
|
||||
bool output_signed = true;
|
||||
FastPID myPID(Kp, Ki, Kd, Hz, output_bits, output_signed);
|
||||
FastPID myPID_0(Kp, Ki, Kd, Hz, output_bits, output_signed);
|
||||
FastPID myPID_1(Kp, Ki, Kd, Hz, output_bits, output_signed);
|
||||
FastPID myPID_2(Kp, Ki, Kd, Hz, output_bits, output_signed);
|
||||
FastPID myPID_3(Kp, Ki, Kd, Hz, output_bits, output_signed);
|
||||
|
||||
void moteur_set(int i); // fonction de gestion de vitesse et position moteurs
|
||||
void moteur_set(int i); // fonction de gestion de vitesse et position moteurs avec ou sans PID
|
||||
void moteur_stop(int i); // fonction d'arret moteurs
|
||||
|
||||
void moteur_stop(int i)
|
||||
void moteur_stop(int i) // fonction d'arret moteurs
|
||||
{
|
||||
myPID.clear(); // remise à zéro du PID
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
myPID_0.clear(); // remise à zéro du PID
|
||||
break;
|
||||
case 1:
|
||||
myPID_1.clear(); // remise à zéro du PID
|
||||
|
||||
break;
|
||||
case 2:
|
||||
myPID_2.clear(); // remise à zéro du PID
|
||||
|
||||
break;
|
||||
case 3:
|
||||
myPID_3.clear(); // remise à zéro du PID
|
||||
break;
|
||||
}
|
||||
motor_speed[i] = 0; // remise à zéro de la vitesse du moteur
|
||||
motor[i].stop(); // stop moteur
|
||||
//delay(100); // attente 100ms
|
||||
motor_change[i] = false; // remise à zéro du flag de changement de position du potentiomètre
|
||||
lecture_pot(i); // lecture analogique du potentiomètre
|
||||
position_set[i] = position_lue[i]; // remise à zéro de la consigne de position du potentiomètre
|
||||
save_pot(i); // sauvegarde position potentiomètre
|
||||
last_motor_end[i] = millis();
|
||||
#ifdef DEBUG // si DEBUG activé
|
||||
breakpoint();
|
||||
#endif
|
||||
last_motor_end = millis(); // sauvegarde du temps d'arrêt du moteur
|
||||
}
|
||||
|
||||
void moteur_set(int i)
|
||||
void moteur_set(int i) // fonction de gestion de vitesse et position moteurs avec ou sans PID
|
||||
{
|
||||
|
||||
if (position_lue[i] <= (position_set[i] + ECART_V_STOP) && position_lue[i] >= (position_set[i] - ECART_V_STOP)) // si moteur entre consigne et ECART_V_STOP
|
||||
{
|
||||
motor[i].brake(); // frein moteur
|
||||
motor[i].brake(); // frein moteur
|
||||
motor_speed[i] = 0;
|
||||
error_state = false; // remise à zéro du flag d'erreur
|
||||
moteur_stop(i); // stop moteur
|
||||
return;
|
||||
}
|
||||
else if (position_set[i] <= (min_val_pot + ECART_V_MIN_MAX) && position_lue[i] <= (position_set[i] + ECART_V_MIN_MAX)) // si moteur est a la position min
|
||||
{
|
||||
motor[i].brake(); // frein moteur
|
||||
motor_speed[i] = 0;
|
||||
error_state = false; // remise à zéro du flag d'erreur
|
||||
moteur_stop(i); // stop moteur
|
||||
return;
|
||||
}
|
||||
else if (position_set[i] >= (max_val_pot) && position_lue[i] >= (position_set[i])) // si moteur est a la position max
|
||||
{
|
||||
motor[i].brake(); // frein moteur
|
||||
motor_speed[i] = 0;
|
||||
error_state = false; // remise à zéro du flag d'erreur
|
||||
moteur_stop(i); // stop moteur
|
||||
return;
|
||||
@@ -53,64 +93,148 @@ void moteur_set(int i)
|
||||
// *******************************************************************************************************
|
||||
else if (position_lue[i] > position_set[i]) // si moteur doit aller vers la gauche
|
||||
{
|
||||
myPID.configure(Kp, Ki, Kd, Hz, output_bits, output_signed); // configuration PID
|
||||
myPID.setOutputRange(-PID_speed_max, -PID_speed_min); // plage de sortie du PID
|
||||
error_state = false; // remise à zéro du flag d'erreur
|
||||
if (position_lue[i] >= position_set[i] + ECART_V_SPEED_PID) // vitesse PID si moteur n'est pas entre consigne et ECART_V_SPEED_PID
|
||||
// myPID.configure(Kp, Ki, Kd, Hz, output_bits, output_signed); // configuration PID
|
||||
switch (i) // configuration PID en fonction du moteur (i)
|
||||
{
|
||||
motor_speed[i] = myPID.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
case 0:
|
||||
myPID_0.setOutputRange(-PID_speed_max, -PID_speed_min); // plage de sortie du PID
|
||||
break;
|
||||
case 1:
|
||||
myPID_1.setOutputRange(-PID_speed_max, -PID_speed_min); // plage de sortie du PID
|
||||
|
||||
break;
|
||||
case 2:
|
||||
myPID_2.setOutputRange(-PID_speed_max, -PID_speed_min); // plage de sortie du PID
|
||||
|
||||
break;
|
||||
case 3:
|
||||
myPID_3.setOutputRange(-PID_speed_max, -PID_speed_min); // plage de sortie du PID
|
||||
break;
|
||||
}
|
||||
else if (position_lue[i] < position_set[i] + ECART_V_SPEED_PID && position_lue[i] > position_set[i] + ECART_V_STOP)
|
||||
error_state = false; // remise à zéro du flag d'erreur
|
||||
if (position_set[i] <= min_val_pot + ECART_V_MIN_MAX) // si consigne de position du potentiomètre = min
|
||||
{
|
||||
// motor[i].brake(); // frein moteur pour inertie moteur
|
||||
motor_speed[i] = -speed_min; // vitesse min moteur
|
||||
myPID.clear(); // remise à zéro du PID
|
||||
motor_speed[i] = -63;
|
||||
switch (i) // mise à zéro du PID en fonction du moteur (i)
|
||||
{
|
||||
case 0:
|
||||
myPID_0.clear(); // remise à zéro du PID
|
||||
break;
|
||||
case 1:
|
||||
myPID_1.clear(); // remise à zéro du PID
|
||||
break;
|
||||
case 2:
|
||||
myPID_2.clear(); // remise à zéro du PID
|
||||
|
||||
break;
|
||||
case 3:
|
||||
myPID_3.clear(); // remise à zéro du PID
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (position_lue[i] >= position_set[i] + ECART_V_STOP) // vitesse PID si moteur n'est pas entre consigne et ECART_V_STOP
|
||||
{
|
||||
switch (i) // calcul de la vitesse moteur en fonction du moteur (i)
|
||||
{
|
||||
case 0:
|
||||
motor_speed[i] = myPID_0.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
case 1:
|
||||
motor_speed[i] = myPID_1.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
case 2:
|
||||
motor_speed[i] = myPID_2.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
case 3:
|
||||
motor_speed[i] = myPID_3.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
motor_speed[i] = 0;
|
||||
motor[i].brake(); // frein moteur pour inertie moteur
|
||||
moteur_stop(i); // stop moteur
|
||||
}
|
||||
if (position_set[i] <= min_pot[i] + ECART_V_MIN_MAX) // si consigne de position du potentiomètre = 0
|
||||
{
|
||||
position_set[i] = min_pot[i];
|
||||
|
||||
motor_speed[i] = -63;
|
||||
return;
|
||||
}
|
||||
motor[i].drive(motor_speed[i]); // controle moteur
|
||||
}
|
||||
// *******************************************************************************************************
|
||||
else if (position_lue[i] < position_set[i]) // si moteur doit aller vers la droite
|
||||
{
|
||||
myPID.configure(Kp, Ki, Kd, Hz, output_bits, output_signed); // configuration PID
|
||||
myPID.setOutputRange(PID_speed_min, PID_speed_max); // plage de sortie du PID
|
||||
error_state = false; // remise à zéro du flag d'erreur
|
||||
if (position_lue[i] <= position_set[i] - ECART_V_SPEED_PID) // vitesse PID si moteur n'est pas entre consigne et ECART_V_SPEED_PID
|
||||
// myPID.configure(Kp, Ki, Kd, Hz, output_bits, output_signed); // configuration PID
|
||||
switch (i)
|
||||
{
|
||||
motor_speed[i] = myPID.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
case 0:
|
||||
myPID_0.setOutputRange(PID_speed_min, PID_speed_max); // plage de sortie du PID
|
||||
break;
|
||||
case 1:
|
||||
myPID_1.setOutputRange(PID_speed_min, PID_speed_max); // plage de sortie du PID
|
||||
|
||||
break;
|
||||
case 2:
|
||||
myPID_2.setOutputRange(PID_speed_min, PID_speed_max); // plage de sortie du PID
|
||||
|
||||
break;
|
||||
case 3:
|
||||
myPID_3.setOutputRange(PID_speed_min, PID_speed_max); // plage de sortie du PID
|
||||
break;
|
||||
}
|
||||
else if (position_lue[i] > position_set[i] - ECART_V_SPEED_PID && position_lue[i] < position_set[i] - ECART_V_STOP)
|
||||
error_state = false; // remise à zéro du flag d'erreur
|
||||
|
||||
if (position_set[i] >= max_val_pot - ECART_V_MIN_MAX) // si consigne de position du potentiomètre = max
|
||||
{
|
||||
// motor[i].brake(); // frein moteur pour inertie moteur
|
||||
motor_speed[i] = speed_min; // vitesse min moteur
|
||||
myPID.clear(); // remise à zéro du PID
|
||||
motor_speed[i] = 63;
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
myPID_0.clear(); // remise à zéro du PID
|
||||
break;
|
||||
case 1:
|
||||
myPID_1.clear(); // remise à zéro du PID
|
||||
|
||||
break;
|
||||
case 2:
|
||||
myPID_2.clear(); // remise à zéro du PID
|
||||
|
||||
break;
|
||||
case 3:
|
||||
myPID_3.clear(); // remise à zéro du PID
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (position_lue[i] <= position_set[i] - ECART_V_STOP) // vitesse PID si moteur n'est pas entre consigne et ECART_V_STOP
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
motor_speed[i] = myPID_0.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
case 1:
|
||||
motor_speed[i] = myPID_1.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
case 2:
|
||||
motor_speed[i] = myPID_2.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
case 3:
|
||||
motor_speed[i] = myPID_3.step(position_set[i], position_lue[i]); // vitesse moteur par PID
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
motor_speed[i] = 0;
|
||||
motor[i].brake(); // frein moteur pour inertie moteur
|
||||
moteur_stop(i); // stop moteur
|
||||
}
|
||||
if (position_set[i] >= max_pot[i] - ECART_V_MIN_MAX) // si consigne de position du potentiomètre = 0
|
||||
{
|
||||
position_set[i] = max_pot[i];
|
||||
motor_speed[i] = 63;
|
||||
return;
|
||||
}
|
||||
motor[i].drive(motor_speed[i]); // controle moteur
|
||||
}
|
||||
else
|
||||
{
|
||||
error_state = true; // flag d'erreur
|
||||
motor[i].brake(); // frein moteur
|
||||
motor_speed[i] = 0;
|
||||
motor[i].brake(); // frein moteur
|
||||
moteur_stop(i);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
/*
|
||||
|
||||
*/
|
||||
@@ -12,26 +12,52 @@ Gestion de la lecture des potentiomètres et des boutons
|
||||
// but doing so may cause more noise to seep through if sleep is not enabled
|
||||
#include <ResponsiveAnalogRead.h>
|
||||
|
||||
#define amount_easing 0.8 // valeur d'atténuation du potentiomètre
|
||||
#define amount_easing 0.1 // valeur d'atténuation du potentiomètre
|
||||
#define sleep_mode true // true = mode sleep activé, false = mode sleep désactivé
|
||||
ResponsiveAnalogRead gain_0(gain_0_pot, sleep_mode, amount_easing);
|
||||
ResponsiveAnalogRead vol_0(vol_0_pot, sleep_mode, amount_easing);
|
||||
ResponsiveAnalogRead gain_1(gain_1_pot, sleep_mode, amount_easing);
|
||||
ResponsiveAnalogRead vol_1(vol_1_pot, sleep_mode, amount_easing);
|
||||
|
||||
ResponsiveAnalogRead gain_0(gain_0_pot, true, amount_easing);
|
||||
ResponsiveAnalogRead vol_0(vol_0_pot, true, amount_easing);
|
||||
ResponsiveAnalogRead gain_1(gain_1_pot, true, amount_easing);
|
||||
ResponsiveAnalogRead vol_1(vol_1_pot, true, amount_easing);
|
||||
void save_pot(int i); // sauvegarde position potentiomètre
|
||||
void lecture_pot(int i); // lecture analogique potentiomètre
|
||||
void adapt_pot(int value, int i); // adaptation de la valeur du potentiomètre
|
||||
|
||||
void save_pot(int i); // sauvegarde position potentiomètre
|
||||
void lecture_pot(int i); // lecture analogique potentiomètre
|
||||
|
||||
void save_pot(int i)
|
||||
void save_pot(int i) // sauvegarde position potentiomètre
|
||||
{
|
||||
position_save[i] = position_lue[i]; // sauvegarde position potentiomètre
|
||||
position_change[i] = false; // RAZ flag de changement de position du potentiomètre
|
||||
}
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** lecture bouton *********************************************
|
||||
// *******************************************************************************************************
|
||||
void lecture_pot(int i)
|
||||
#define offset_pot 1 // valeur de décalage de mise à jour du potentiomètre
|
||||
#define nb_count_pot 1 // nombre de lecture du potentiomètre avant mise à jour
|
||||
|
||||
void adapt_pot(int value, int i)
|
||||
{
|
||||
last_pot_change[i] = millis();
|
||||
valut_pot_old[i] = value;
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
int map_value = map(value, max_pot[i], min_pot[i], min_val_pot, max_val_pot);
|
||||
//map_value = map_value / divider_analog;
|
||||
#ifdef CALIBRATED
|
||||
if (map_value <= calibrating_midle_pot[i])
|
||||
map_value = map(map_value, 0, calibrating_midle_pot[i], min_val_pot, middle_value);
|
||||
else if (map_value > calibrating_midle_pot[i])
|
||||
map_value = map(map_value, calibrating_midle_pot[i], max_val_pot, middle_value + 1, max_val_pot);
|
||||
#endif
|
||||
position_lue[i] = constrain(map_value, min_val_pot, max_val_pot);
|
||||
|
||||
Serial.print("position_lue[");
|
||||
Serial.print(i);
|
||||
Serial.print("] = ");
|
||||
Serial.println(position_lue[i]);
|
||||
Serial.print("map_value = ");
|
||||
Serial.println(map_value);
|
||||
Serial.print("value = ");
|
||||
Serial.println(value);
|
||||
}
|
||||
|
||||
void lecture_pot(int i) // lecture analogique potentiomètre
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
@@ -39,10 +65,13 @@ void lecture_pot(int i)
|
||||
gain_0.update();
|
||||
if (gain_0.hasChanged())
|
||||
{
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
Serial.print("gain_0.getValue() = ");
|
||||
Serial.println(gain_0.getValue());
|
||||
int value = gain_0.getValue();
|
||||
int map_value = map(value, max_pot[i], min_pot[i], 0, 1023);
|
||||
position_lue[i] = constrain(map_value, 0, 1023);
|
||||
if (value > valut_pot_old[i] + offset_pot or value < valut_pot_old[i] - offset_pot)
|
||||
count_pot_change[i]++;
|
||||
if (count_pot_change[i] > nb_count_pot)
|
||||
adapt_pot(value, i);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -50,10 +79,13 @@ void lecture_pot(int i)
|
||||
vol_0.update();
|
||||
if (vol_0.hasChanged())
|
||||
{
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
Serial.print("vol_0.getValue() = ");
|
||||
Serial.println(vol_0.getValue());
|
||||
int value = vol_0.getValue();
|
||||
int map_value = map(value, max_pot[i], min_pot[i], 0, 1023);
|
||||
position_lue[i] = constrain(map_value, 0, 1023);
|
||||
if (value > valut_pot_old[i] + offset_pot or value < valut_pot_old[i] - offset_pot)
|
||||
count_pot_change[i]++;
|
||||
if (count_pot_change[i] > nb_count_pot)
|
||||
adapt_pot(value, i);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -61,10 +93,13 @@ void lecture_pot(int i)
|
||||
gain_1.update();
|
||||
if (gain_1.hasChanged())
|
||||
{
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
Serial.print("gain_1.getValue() = ");
|
||||
Serial.println(gain_1.getValue());
|
||||
int value = gain_1.getValue();
|
||||
int map_value = map(value, max_pot[i], min_pot[i], 0, 1023);
|
||||
position_lue[i] = constrain(map_value, 0, 1023);
|
||||
if (value > valut_pot_old[i] + offset_pot or value < valut_pot_old[i] - offset_pot)
|
||||
count_pot_change[i]++;
|
||||
if (count_pot_change[i] > nb_count_pot)
|
||||
adapt_pot(value, i);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -72,10 +107,13 @@ void lecture_pot(int i)
|
||||
vol_1.update();
|
||||
if (vol_1.hasChanged())
|
||||
{
|
||||
position_change[i] = true; // il y a changement de position du potentiomètre
|
||||
Serial.print("vol_1.getValue() = ");
|
||||
Serial.println(vol_1.getValue());
|
||||
int value = vol_1.getValue();
|
||||
int map_value = map(value, max_pot[i], min_pot[i], 0, 1023);
|
||||
position_lue[i] = constrain(map_value, 0, 1023);
|
||||
if (value > valut_pot_old[i] + offset_pot or value < valut_pot_old[i] - offset_pot)
|
||||
count_pot_change[i]++;
|
||||
if (count_pot_change[i] > nb_count_pot)
|
||||
adapt_pot(value, i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2,32 +2,31 @@
|
||||
gestion des valeurs selon position de gain et volume, lissage des valeurs et mise à jour des relais
|
||||
*******************************************************************************************************/
|
||||
|
||||
|
||||
void valeurs_set(int i); // gestion des valeurs
|
||||
void valeurs_const_set(int i); // gestion des valeurs constant ouptut
|
||||
void smoothgain_set(int i); // calcul des valeurs lissées de gain et mise à jour des relais
|
||||
void smoothvolume_set(int i); // calcul des valeurs lissées de volume et mise à jour des relais
|
||||
|
||||
void valeurs_set(int i)
|
||||
void valeurs_set(int i) // gestion des valeurs
|
||||
{
|
||||
if (position_change[i] == true && position_lue[i] != position_save[i]) // si changement d'état du potentiomètre
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
smoothgain[0] = byte(position_lue[0] / 4); // adaptation de valeur
|
||||
smoothgain[0] = byte(position_lue[0] / divider_relais); // adaptation de valeur
|
||||
smoothgain_set(0); // mise à jour de valeur du relais gain gauche
|
||||
break;
|
||||
case 1:
|
||||
smoothvol[0] = byte(position_lue[1] / 4) - 1; // adaptation de valeur
|
||||
smoothvolume_set(0);
|
||||
smoothvol[0] = byte(position_lue[1] / divider_relais) - 1; // adaptation de valeur
|
||||
smoothvolume_set(0); // mise à jour de valeur du relais volume gauche
|
||||
break;
|
||||
case 2:
|
||||
smoothgain[1] = byte(position_lue[2] / 4); // adaptation de valeur
|
||||
smoothgain[1] = byte(position_lue[2] / divider_relais); // adaptation de valeur
|
||||
smoothgain_set(1); // mise à jour de valeur du relais gain droit
|
||||
break;
|
||||
case 3:
|
||||
smoothvol[1] = byte(position_lue[3] / 4) - 1; // adaptation de valeur
|
||||
smoothvol[1] = byte(position_lue[3] / divider_relais) - 1; // adaptation de valeur
|
||||
smoothvolume_set(1); // mise à jour de valeur du relais volume droit
|
||||
break;
|
||||
default:
|
||||
@@ -36,26 +35,26 @@ void valeurs_set(int i)
|
||||
}
|
||||
}
|
||||
|
||||
void valeurs_const_set(int i)
|
||||
void valeurs_const_set(int i) // gestion des valeurs constant output
|
||||
{
|
||||
if (position_set[i] != position_save[i]) // si changement d'état du potentiomètre
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
smoothgain[0] = byte(position_set[0] / 4); // adaptation de valeur
|
||||
smoothgain[0] = byte(position_set[0] / divider_relais); // adaptation de valeur
|
||||
smoothgain_set(0); // mise à jour de valeur du relais gain gauche
|
||||
break;
|
||||
case 1:
|
||||
smoothvol[0] = byte(position_set[1] / 4) - 1; // adaptation de valeur
|
||||
smoothvol[0] = byte(position_set[1] / divider_relais) - 1; // adaptation de valeur
|
||||
smoothvolume_set(0); // mise à jour de valeur du relais volume gauche
|
||||
break;
|
||||
case 2:
|
||||
smoothgain[1] = byte(position_set[2] / 4); // adaptation de valeur
|
||||
smoothgain[1] = byte(position_set[2] / divider_relais); // adaptation de valeur
|
||||
smoothgain_set(1); // mise à jour de valeur du relais gain droit
|
||||
break;
|
||||
case 3:
|
||||
smoothvol[1] = byte(position_set[3] / 4) - 1; // adaptation de valeur
|
||||
smoothvol[1] = byte(position_set[3] / divider_relais) - 1; // adaptation de valeur
|
||||
smoothvolume_set(1); // mise à jour de valeur du relais volume droit
|
||||
break;
|
||||
default:
|
||||
@@ -64,9 +63,8 @@ void valeurs_const_set(int i)
|
||||
}
|
||||
}
|
||||
|
||||
void smoothgain_set(int i)
|
||||
void smoothgain_set(int i) // calcul des valeurs lissées de gain et mise à jour des relais
|
||||
{
|
||||
// lisages manuel des valeurs de gain
|
||||
smoothgain[i] = map(smoothgain[i], 0, 255, 0, 156); // 156sm
|
||||
{
|
||||
relais_gain_val[i] = smoothgain[i];
|
||||
@@ -363,27 +361,29 @@ void smoothgain_set(int i)
|
||||
{
|
||||
relais_gain_val[i] = smoothgain[i] + 99;
|
||||
}
|
||||
// mise à jour des relais
|
||||
if (i == 0)
|
||||
{
|
||||
relais_set(0); // mise à jour des relais
|
||||
relais_set(0); // relais volume gauche
|
||||
}
|
||||
if (i == 1)
|
||||
{
|
||||
relais_set(2); // mise à jour des relais
|
||||
relais_set(2); // relais volume droit
|
||||
}
|
||||
}
|
||||
|
||||
void smoothvolume_set(int i)
|
||||
void smoothvolume_set(int i) // calcul des valeurs lissées de volume et mise à jour des relais
|
||||
{
|
||||
smoothvol[i] = map(smoothvol[i], 0, 255, 0, 255); // map de 0 à 255
|
||||
smoothvol[i] = constrain(smoothvol[i], 0, 255); // map de 0 à 255
|
||||
smoothvol[i] = constrain(smoothvol[i], 0, 255); // constrain de 0 à 255
|
||||
relais_vol_val[i] = smoothvol[i]; // valeur du relais = valeur du volume
|
||||
// mise à jour des relais
|
||||
if (i == 0)
|
||||
{
|
||||
relais_set(1); // mise à jour des relais
|
||||
relais_set(1); // relais gain gauche
|
||||
}
|
||||
if (i == 1)
|
||||
{
|
||||
relais_set(3); // mise à jour des relais
|
||||
relais_set(3); // relais gain droit
|
||||
}
|
||||
}
|
||||
@@ -22,36 +22,100 @@
|
||||
// *******************************************************************************************************
|
||||
// variables potentiomètre
|
||||
int position_lue[4] = {0, 0, 0, 0}; // tableau des valeur lus sur les potentiomètre
|
||||
int valut_pot_old[4] = {0, 0, 0, 0}; // tableau de comparaison de valeur lus sur les potentiomètre
|
||||
int position_save[4] = {0, 0, 0, 0}; // tableau de sauvegarde de valeurs des potentiomètre pour comparaison
|
||||
int position_set[4] = {0, 0, 0, 0}; // tableau de consigne de position des potentiomètre
|
||||
int position_memory[4] = {0, 0, 0, 0}; // tableau de memorisation de valeur des potentiomètre pour mode constant output
|
||||
bool position_change[4] = {false, false, false, false}; // tableau de flag de changement de position des potentiomètre
|
||||
bool motor_change[4] = {false, false, false, false}; // tableau de flag pour moteurs des potentiomètre
|
||||
bool motor_change[4] = {false, false, false, false}; // tableau de flag d'enclenchement des moteurs de potentiomètre
|
||||
byte analog_pot[4] = {gain_0_pot, vol_0_pot, gain_1_pot, vol_1_pot}; // tableau de PIN des potentiomètre
|
||||
|
||||
int max_pot[4] = {1023, 1023, 1023, 1023}; // valeur max potentiomètre pour calibrage ADC
|
||||
int min_pot[4] = {0, 0, 0, 0}; // valeur min potentiomètre pour calibrage ADC
|
||||
#define bounce_time_pot 200 // interval de temps entre 2 lecture de l'état du potentiomètre
|
||||
// réglagle de précision de lecture du potentiomètre
|
||||
#define bit_read_pot 4 // 4 = 10 bits, 2 = 9 bits, 1 = 8 bits
|
||||
/*
|
||||
Max-val_pot / divider relais / divider_analog
|
||||
255 / 1 / 4
|
||||
512 / 2 / 2
|
||||
1023 / 4 / 1
|
||||
*/
|
||||
|
||||
#if bit_read_pot == 4
|
||||
#define divider_relais 1
|
||||
#define divider_analog 4
|
||||
#define max_val_pot 255 // valeur max du potentiomètre
|
||||
#elif bit_read_pot == 2
|
||||
#define divider_relais 2
|
||||
#define divider_analog 2
|
||||
#define max_val_pot 512 // valeur max du potentiomètre
|
||||
#elif bit_read_pot == 1
|
||||
#define divider_relais 4
|
||||
#define divider_analog 1
|
||||
#define max_val_pot 1023 // valeur max du potentiomètre
|
||||
#endif
|
||||
|
||||
#define min_val_pot 0 // valeur min du potentiomètre
|
||||
#define offset_max_pot 0 // valeur de suppression de la valeur max du potentiomètre (lecture à 0% de la course)
|
||||
#define offset_min_pot 5 // valeur d'ajout de la valeur min du potentiomètre (lecture à 100% de la course)
|
||||
|
||||
const int middle_value = max_val_pot / 2; // valeur du milieu du potentiomètre
|
||||
|
||||
unsigned long max_pot_time[4] = {0, 0, 0, 0}; // compteur de temps de maintien moteur pour la valeur max du potentiomètre
|
||||
unsigned long last_pot_change[4] = {0, 0, 0, 0}; // compteur de temps de changement de valeur du potentiomètre
|
||||
int count_pot_change[4] = {1, 1, 1, 1}; // compteur de changement de valeur du potentiomètre
|
||||
// int max_pot[4] = {max_val_pot - offset_max_pot, max_val_pot - offset_max_pot, max_val_pot - offset_max_pot, max_val_pot - offset_max_pot}; // valeur max potentiomètre pour calibrage ADC
|
||||
// int min_pot[4] = {min_val_pot + offset_min_pot, min_val_pot + offset_min_pot, min_val_pot + offset_min_pot, min_val_pot + offset_min_pot}; // valeur min potentiomètre pour calibrage ADC
|
||||
|
||||
int max_pot[4] = {1023, 1022, 1014, 1014}; // valeur max potentiomètre pour calibrage ADC
|
||||
int min_pot[4] = {30, 29, 20, 21}; // valeur min potentiomètre pour calibrage ADC
|
||||
|
||||
#define CALIBRATED
|
||||
|
||||
#ifdef CALIBRATED
|
||||
#define value_middle_pot_0 109
|
||||
#define value_middle_pot_1 117
|
||||
#define value_middle_pot_2 130
|
||||
#define value_middle_pot_3 134
|
||||
|
||||
int calibrating_midle_pot[4] = {value_middle_pot_0, value_middle_pot_1, value_middle_pot_2, value_middle_pot_3};
|
||||
#else
|
||||
int calibrating_midle_pot[4] = {middle_value, middle_value, middle_value, middle_value};
|
||||
#endif
|
||||
|
||||
#define bounce_time_pot 200 // interval de temps entre 2 lecture de l'état du potentiomètre
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** moteur *****************************************************
|
||||
// *******************************************************************************************************
|
||||
// adressage I2C carte moteur
|
||||
#define gain_0_motor 0xC8 // A0 = open, A1 = open
|
||||
#define vol_0_motor 0xCE // A0 = open, A1 = 1
|
||||
#define gain_1_motor 0xC2 // A0 = open, A1 = 0
|
||||
#define vol_1_motor 0xC6 // A0 = 0, A1 = open
|
||||
int motor_speed[4] = {0, 0, 0, 0}; // tableau de valeur de vitesse des moteur
|
||||
unsigned long last_motor_end[4] = {0, 0, 0, 0}; // compteur de temps d'arrêt moteur
|
||||
/*
|
||||
0xC8 : A0 = open, A1 = open
|
||||
0xCE : A0 = open, A1 = 1
|
||||
0xC2 : A0 = open, A1 = 0
|
||||
0xC6 : A0 = 0, A1 = open
|
||||
*/
|
||||
#define gain_0_motor 0xC6
|
||||
#define vol_0_motor 0xC8
|
||||
#define gain_1_motor 0xC2
|
||||
#define vol_1_motor 0xCE
|
||||
|
||||
int motor_speed[4]; // tableau de valeur de vitesse des moteur
|
||||
unsigned long last_motor_end = 0; // compteur de temps d'arrêt moteur
|
||||
// unsigned long last_motor_end[4] = {0, 0, 0, 0}; // compteur de temps d'arrêt moteur
|
||||
|
||||
// *******************************************************************************************************
|
||||
// ****************************************** relais *****************************************************
|
||||
// *******************************************************************************************************
|
||||
// adressage I2C carte relais
|
||||
#define gain_0_relais 0x39 // A0 = 0, A1 = 1, A2 = 1
|
||||
#define vol_0_relais 0x38 // A0 = 1, A1 = 1, A2 = 1
|
||||
#define gain_1_relais 0x3B // A0 = 0, A1 = 0, A2 = 1
|
||||
#define vol_1_relais 0x3A // A0 = 1, A1 = 0, A2 = 1
|
||||
/*
|
||||
0x39 : A0 = 0, A1 = 1, A2 = 1
|
||||
0x38 : A0 = 1, A1 = 1, A2 = 1
|
||||
0x3B : A0 = 0, A1 = 0, A2 = 1
|
||||
0x3A : A0 = 1, A1 = 0, A2 = 1
|
||||
*/
|
||||
#define gain_0_relais 0x39
|
||||
#define vol_0_relais 0x38
|
||||
#define gain_1_relais 0x3B
|
||||
#define vol_1_relais 0x3A
|
||||
|
||||
// variables relais
|
||||
byte relais_gain_val[2] = {0, 0}; // tableau de valeur des relais gain
|
||||
@@ -88,7 +152,7 @@ bool error_led_state = LOW;
|
||||
|
||||
unsigned long old_led_time = millis(); // variable de temps courant
|
||||
|
||||
void error_led()
|
||||
void error_led() // fonction clignotement LED en cas d'erreur
|
||||
{
|
||||
unsigned long current_led_time = millis(); // variable de temps courant
|
||||
if (current_led_time - old_led_time >= 100)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/Users/electron_rare/Documents/Lelectron_rare/HLabs/HLabs_analog_felling/PCB/PCB Hlabs motor cotrol/_autosave-Hlabs motor cotrol.kicad_sch
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -72,31 +72,6 @@
|
||||
"version": 3
|
||||
},
|
||||
"project": {
|
||||
"files": [
|
||||
{
|
||||
"name": "Hlabs motor cotrol.kicad_pcb",
|
||||
"open": false,
|
||||
"window": {
|
||||
"display": 0,
|
||||
"maximized": false,
|
||||
"pos_x": 119,
|
||||
"pos_y": 89,
|
||||
"size_x": 1496,
|
||||
"size_y": 883
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Hlabs motor cotrol.kicad_sch",
|
||||
"open": false,
|
||||
"window": {
|
||||
"display": 0,
|
||||
"maximized": true,
|
||||
"pos_x": 116,
|
||||
"pos_y": 107,
|
||||
"size_x": 1496,
|
||||
"size_y": 880
|
||||
}
|
||||
}
|
||||
]
|
||||
"files": []
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
{"hostname":"Mac-de-clems","username":"electron_rare"}
|
||||
@@ -0,0 +1 @@
|
||||
{"hostname":"Mac-de-clems","username":"electron_rare"}
|
||||
Reference in New Issue
Block a user