new file: .gitignore

new file:   .vscode/extensions.json
	new file:   .vscode/settings.json
	new file:   platformio.ini
	new file:   src/.DS_Store
	new file:   src/bouton.h
	new file:   src/const_set.h
	new file:   src/main.cpp
	new file:   src/moteur.h
	new file:   src/notepad.txt
	new file:   src/pot.h
	new file:   src/relais.h
	new file:   src/valeurs.h
	new file:   src/variables.h
This commit is contained in:
Clément SAILLANT
2023-01-25 17:52:01 +01:00
commit 0feb1aace4
25 changed files with 2023 additions and 0 deletions
Vendored
BIN
View File
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
+10
View File
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"C_Cpp.errorSquiggles": "disabled"
}
+32
View File
@@ -0,0 +1,32 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:uno]
platform = atmelavr
board = uno
framework = arduino
upload_port = /dev/cu.usbmodem1101
monitor_speed = 115200
monitor_filters = colorize
lib_deps =
sparkfun/SparkFun MiniMoto@^1.1.0
Wire
dxinteractive/ResponsiveAnalogRead @ ^1.2.1
thomasfredericks/Bounce2 @ ^2.71
robtillaart/PCF8574 @ ^0.3.7
https://github.com/thijse/Arduino-Log
thijse/ArduinoLog @ ^1.1.1
donnycraft1/PIDController @ ^0.0.1
r-downing/AutoPID @ ^1.0.3
dlloydev/QuickPID @ ^3.1.4
powerbroker2/FireTimer @ ^1.0.5
[platformio]
description = Digitally Controlled Full Analog Gain Stage
BIN
View File
Binary file not shown.
+143
View File
@@ -0,0 +1,143 @@
// *******************************************************************************************************
// ****************************************** gestion bouttons ********************************************
// *******************************************************************************************************
// Include the Bounce2 library found here :
// https://github.com/thomasfredericks/Bounce2
#include <Bounce2.h>
// création instance bouton
Bounce2::Button const_out_L = Bounce2::Button(); // instance du bouton const_out_L
Bounce2::Button const_out_R = Bounce2::Button(); // instance du bouton const_out_R
Bounce2::Button stereo_link = Bounce2::Button(); // instance du bouton stereo_link
void lecture_switch(); // lecture bouton
void bouton_set(); // gestion des boutons
void stereo_link_set(); // gestion du bouton stereo_link
void const_out_L_set(); // gestion du bouton const_out_L
void const_out_R_set(); // gestion du bouton const_out_R
void lecture_switch()
{
// lecture des boutons
const_out_L.update();
const_out_R.update();
stereo_link.update();
// mise à jour des états des boutons
if (const_out_L.pressed())
{
const_out_L_state = !const_out_L_state;
}
if (const_out_R.pressed())
{
const_out_R_state = !const_out_R_state;
}
if (stereo_link.pressed())
{
stereo_link_state = !stereo_link_state;
}
}
void bouton_set()
{
lecture_switch();
if (stereo_link_state_old != stereo_link_state) // si changement d'état du bouton stereo_link
{
stereo_link_set(); // gestion du bouton stereo_link
state_button_change = 1; // il y a changement d'état d'un bouton
stereo_link_state_old = stereo_link_state; // sauvegarde état bouton stereo_link
}
if (const_out_L_state_old != const_out_L_state) // si changement d'état du bouton const_out_L
{
const_out_L_set(); // gestion du bouton const_out_L
if (stereo_link_state == 1) // si bouton stereo_link appuyé
{
const_out_R_state = const_out_L_state; // copie état bouton const_out_L
const_out_R_state_old = const_out_L_state; // sauvegarde copie état bouton const_out_R
}
state_button_change = 1; // il y a changement d'état d'un bouton
const_out_L_state_old = const_out_L_state; // sauvegarde état bouton const_out_L
}
if (const_out_R_state_old != const_out_R_state) // si changement d'état du bouton const_out_R
{
const_out_R_set(); // gestion du bouton const_out_R
if (stereo_link_state == 1) // si bouton stereo_link appuyé
{
const_out_L_state = const_out_R_state; // copie état bouton const_out_R
const_out_L_state_old = const_out_R_state; // sauvegarde copie état bouton const_out_L
}
state_button_change = 1; // il y a changement d'état d'un bouton
const_out_R_state_old = const_out_R_state; // sauvegarde état bouton const_out_R
}
#ifdef DEBUG_BOUTON // si DEBUG activé
if (state_button_change == true)
{
Log.notice("bouton_change" CR);
Log.trace("const_out_L_state = %d" CR, const_out_L_state);
Log.trace("const_out_R_state = %d" CR, const_out_R_state);
Log.trace("stereo_link_state = %d" CR, stereo_link_state);
}
#endif
}
void stereo_link_set() // gestion du bouton stereo_link
{
#ifdef DEBUG_BOUTON // si DEBUG activé
Log.notice(F(CR "void stereo_link_set()" CR));
#endif
if (stereo_link_state == 1) // si bouton stereo_link appuyé
{
digitalWrite(stereo_link_led, HIGH); // allume LED stereo_link
if (const_out_L_state == 1 || const_out_R_state == 1) // si bouton const_out_L ou R appuyé
{
const_out_L_state = 1;
const_out_R_state = 1;
}
}
else // si bouton stereo_link relaché
{
digitalWrite(stereo_link_led, LOW); // éteint LED stereo_link
if (const_out_L_state == 0)
{
motor[0].stop(); // arrêt moteur 0
motor[1].stop(); // arrêt moteur 1
motor[2].stop(); // arrêt moteur 2
motor[3].stop(); // arrêt moteur 3
}
}
}
void const_out_L_set() // gestion du bouton const_out_L
{
#ifdef DEBUG_BOUTON // si DEBUG activé
Log.notice(F(CR "void const_out_L_set()" CR));
#endif
if (const_out_L_state == 1) // si bouton const_out_L appuyé
{
digitalWrite(const_out_L_led, HIGH); // allume LED const_out_L
}
else // si bouton const_out_L relaché
{
digitalWrite(const_out_L_led, LOW); // éteint LED const_out_L
motor[0].stop(); // arrêt moteur 0
motor[1].stop(); // arrêt moteur 1
}
}
void const_out_R_set() // gestion du bouton const_out_R
{
#ifdef DEBUG_BOUTON // si DEBUG activé
Log.notice(F(CR "void const_out_R_set()" CR));
#endif
if (const_out_R_state == 1) // si bouton const_out_R appuyé
{
digitalWrite(const_out_R_led, HIGH); // allume LED const_out_R
}
else // si bouton const_out_R relaché
{
digitalWrite(const_out_R_led, LOW); // éteint LED const_out_R
motor[2].stop(); // arrêt moteur 2
motor[3].stop(); // arrêt moteur 3
}
}
+155
View File
@@ -0,0 +1,155 @@
void diff_set(); // calcul des différences de valeurs
void consigne_set(); // calcul des consignes de moteurs
void consigne_calc(int pot, int motor, int position_calc); // calcul des consignes de moteurs
void diff_set() // calcul de la différence entre gain et volume
{
#ifdef DEBUG_DIFF // si DEBUG activé
Log.notice(F("======= void diff set" CR));
#endif
if (const_out_L_state == 1) // si bouton const_out_L appuyé
{
for (int i = 0; i <= 1; i++)
{
lecture_pot(i); // lecture des potentiomètres
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
position_change[i] = false;
save_pot(i); // sauvegarde position potentiomètre
}
diff_const_out_L = position_lue[0] - position_lue[1]; // calcul de la différence entre gain et volume gauche
}
if (const_out_R_state == 1) // si bouton const_out_R appuyé
{
for (int i = 2; i <= 3; i++)
{
lecture_pot(i); // lecture des potentiomètres
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
position_change[i] = false;
save_pot(i); // sauvegarde position potentiomètre
}
diff_const_out_R = position_lue[2] - position_lue[3]; // calcul de la différence entre gain et volume droit
}
if (stereo_link_state == 1) // si bouton stereo_link appuyé
{
for (int i = 0; i <= 3; i++)
{
lecture_pot(i); // lecture des potentiomètres
position_set[i] = position_lue[i]; // set position potentiomètre gain et volume gauche et droit
position_change[i] = false;
save_pot(i); // sauvegarde position potentiomètre
}
diff_gain = position_lue[0] - position_lue[2]; // calcul de la différence entre gain gauche et droit
diff_vol = position_lue[1] - position_lue[3]; // calcul de la différence entre volume gauche et droit
}
#ifdef DEBUG_DIFF // si DEBUG activé
Log.notice(F("diff_const_out_L = %d" CR), diff_const_out_L);
Log.notice(F("diff_const_out_R = %d" CR), diff_const_out_R);
Log.notice(F("diff_gain = %d" CR), diff_gain);
Log.notice(F("diff_vol = %d" CR), diff_vol);
for (int i = 0; i <= 3; i++)
{
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
}
#endif
}
void consign_calc(int pot, int motor, int position_calc) // calcul des consignes de moteurs
{
lecture_pot(pot); // lecture des potentiomètres
lecture_pot(motor); // lecture des potentiomètres
position_set[pot] = position_lue[pot]; // set position potentiomètre gain et volume gauche et droit
#ifdef DEBUG_CONST // si DEBUG activé
Log.notice(F("======= void consigne calc" CR));
Log.notice(F("pot = %d position_lue[%d] = %d" CR), pot, pot, position_lue[pot]);
Log.notice(F("pot = %d position_set[%d] = %d" CR), pot, pot, position_set[pot]);
Log.notice(F("pot = %d position_save[%d] = %d" CR), pot, pot, position_save[pot]);
Log.notice(F("motor = %d position_lue[%d] = %d" CR), motor, motor, position_lue[motor]);
Log.notice(F("motor = %d position_set[%d] = %d" CR), motor, motor, position_set[motor]);
Log.notice(F("motor = %d position_save[%d] = %d" CR), motor, motor, position_save[motor]);
Log.notice(F("motor_change[%d] = %d" CR), motor, motor_change[motor]);
Log.notice(F("pot motor_change[%d] = %d" CR), pot, motor_change[pot]);
Log.notice(F("time elapsed= %d" CR), millis() - last_change_time);
Log.notice(F("bounce_time_pot = %d" CR), bounce_time_pot);
Log.notice(F("position_calc = %d" CR), position_calc);
Log.notice(F("position_calc > (position_lue[motor] + ECRART_V_STOP) = %d" CR), position_calc > (position_lue[motor] + ECRART_V_STOP));
Log.notice(F("position_calc < (position_lue[motor] - ECRART_V_STOP) = %d" CR), position_calc < (position_lue[motor] - ECRART_V_STOP));
#endif
// position_calc = 60
// ecart +
// ecart -
// si changement de position du potentiomètre depuis plus de bounce_time_pot et moteur n'est pas entre consigne et ECRART_V_STOP
if (motor_change[motor] == false && motor_change[pot] == false)
{
if (position_calc >= 1023 || position_calc <= 0) // si consigne n'est pas hors bornes
{
save_pot(pot); // sauvegarde position potentiomètre
save_pot(motor); // sauvegarde position potentiomètre
position_set[motor] = position_lue[motor];
#ifdef DEBUG_CONST // si DEBUG activé
Log.notice(F("======= void consigne HSHSHSHSHSSH calc" CR));
Log.notice(F("diff_const_out_L = %d" CR), diff_const_out_L);
Log.notice(F("============================> position_calc = %d" CR), position_calc);
Log.notice(F("motor = %d" CR), motor);
Log.notice(F("position_lue[motor] = %d" CR), position_lue[motor]);
Log.notice(F("position_set[motor] = %d" CR), position_set[motor]);
Log.notice(F("position_save[motor] = %d" CR), position_save[motor]);
Log.notice(F("pot = %d" CR), pot);
Log.notice(F("position_lue[pot] = %d" CR), position_lue[pot]);
Log.notice(F("position_set[pot] = %d" CR), position_set[pot]);
Log.notice(F("position_save[pot] = %d" CR), position_save[pot]);
#endif
return;
}
else if (position_calc > (position_lue[motor] + ECRART_V_STOP) || position_calc < (position_lue[motor] - ECRART_V_STOP)) // si consigne n'est pas hors bornes
{
position_set[motor] = position_calc; // set position potentiomètre volume gauche
motor_change[motor] = true; // il y a changement de position du potentiomètre de volume gauche
myPID.SetMode(myPID.Control::timer); // set PID en mode automatique
#ifdef DEBUG_CONST // si DEBUG activé
Log.notice(F("======= void consigne YES YES YES calc" CR));
Log.notice(F("position_calc = %d" CR), position_calc);
#endif
}
}
}
void consigne_set() // calcul des consignes de moteurs
{
if (const_out_L_state == true) // si bouton const_out_L appuyé
{
if (state_pot_change[0] == true && motor_change[0] == false && motor_change[1] == false) // si changement de position du potentiomètre de gain gauche et que pas de moteur en mouvement
{
int pot = 0;
int motor = 1;
int position_calc = constrain((position_lue[pot] - diff_const_out_L), 0, 1023); // set position potentiomètre volume gauche
consign_calc(pot, motor, position_calc);
}
if (state_pot_change[1] == true && motor_change[0] == false && motor_change[1] == false) // si changement de position du potentiomètre de volume gauche et que pas de moteur en mouvement
{
int pot = 1;
int motor = 0;
int position_calc = constrain((position_lue[pot] + diff_const_out_L), 0, 1023); // set position potentiomètre volume gauche
consign_calc(pot, motor, position_calc);
}
}
if (const_out_R_state == true) // si bouton const_out_R appuyé
{
}
if (stereo_link_state == true) // si bouton stereo_link appuyé
{
if (const_out_R_state == true || const_out_L_state == true) // si bouton const_out_R ou const_out_L appuyé
{
}
else if (const_out_R_state == true && const_out_L_state == true) // si uniquement stereo_link est appuyé
{
}
else if (const_out_R_state == false && const_out_L_state == false) // si aucun bouton n'est appuyé
{
}
}
}
+217
View File
@@ -0,0 +1,217 @@
/*
Hlabs controle de volume et de gain
par Clément SAILLANT
c.saillant@gmail.com
02/2023
*/
/*
tableau de valeurs (i) pour les relais, les valeurs de potentiomètre et les valeurs de lissage
0 : vol_0 volume gauche
1 : gain_0 gain gauche
2 : vol_1 volume droite
3 : gain_1 gain droite
*/
#include <Arduino.h>
// *******************************************************************************************************
// ******************** pour activer ou non le DEBUG *****************************************************
// ******************** // #define DEBUG = INACTIF *******************************************************
// ******************** #define DEBUG = ACTIF ************************************************************
// *******************************************************************************************************
#define DEBUG
#ifdef DEBUG // si DEBUG activé
#include <ArduinoLog.h>
// #define DEBUG_VOID
#define DEBUG_LOOP
// #define DEBUG_LOOP_HARD
// #define DEBUG_POT
// #define DEBUG_RELAIS
// #define DEBUG_LECTURE
// #define DEBUG_BOUTON
#define DEBUG_MOTEUR
#define DEBUG_MOTEUR_HARD
bool count_motor = false;
// #define DEBUG_VALEURS
#define DEBUG_DIFF
#define DEBUG_CONST
#define DEBUG_PID
bool counter = true;
#endif
// *******************************************************************************************************
// **************************** Activation ou non LEFT & RIGHT *******************************************
// *******************************************************************************************************
#define ENABLE_LEFT
// #define ENABLE_RIGHT
// *******************************************************************************************************
// ****************************************** include ***************************************************
// *******************************************************************************************************
#include "variables.h"
#include "pot.h"
#include "moteur.h"
#include "bouton.h"
#include "relais.h"
#include "valeurs.h"
#include "const_set.h"
// *******************************************************************************************************
// ****************************************** boucle setup ***********************************************
// *******************************************************************************************************
void setup()
{
#ifdef DEBUG // si DEBUG activé
Serial.begin(115200);
// Pass log level, whether to show log level, and print interface.
// Available levels are:
// LOG_LEVEL_SILENT, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_VERBOSE
// Note: if you want to fully remove all logging code, uncomment #define DISABLE_LOGGING in Logging.h
// this will significantly reduce your project size
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
Log.notice(F(CR "Hlabs controle de volume et de gain" CR));
Log.notice("par Clément SAILLANT" CR);
Log.notice("initialisation des variables" CR);
Log.notice("--------------------------------------------------" CR);
#endif
// set LED output
pinMode(const_out_L_led, OUTPUT);
pinMode(const_out_R_led, OUTPUT);
pinMode(stereo_link_led, OUTPUT);
// set bouton const_out_L
pinMode(const_out_sw_L, INPUT_PULLUP);
const_out_L.attach(const_out_sw_L);
const_out_L.interval(interval_button);
const_out_L.setPressedState(LOW);
// set bouton const_out_R
pinMode(const_out_sw_R, INPUT_PULLUP);
const_out_R.attach(const_out_sw_R);
const_out_R.interval(interval_button);
const_out_R.setPressedState(LOW);
// set bouton stereo_link
pinMode(stereo_link_sw, INPUT_PULLUP);
stereo_link.attach(stereo_link_sw);
stereo_link.interval(interval_button);
stereo_link.setPressedState(LOW);
// set motor stop
for (int i = 0; i <= 3; i++)
{
motor[i].stop();
delay(50);
lecture_pot(i); // lecture analogique potentiomètre
save_pot(i); // sauvegarde position potentiomètre
state_pot_change[i] = true;
}
bouton_set(); // lecture et controle des boutons
valeurs_set(); // controle des valeurs et des relais
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
#ifdef PID
myPID.SetMode(myPID.Control::automatic);
// myPID.SetMode(myPID.Control::manual);
// myPID.SetSampleTimeUs(pid_time);
myPID.SetOutputLimits(pid_limit_min, pid_limit_max); // Limit the PID output this is important to get rid of integral windup!
// myPID.setBias(pid_bias / 2.0); // Set the bias to 127.5, this is the center of the output range
// myPID.SetAntiWindupMode(myPID.iAwMode::iAwCondition); // Set the anti-windup mode to "do nothing"
#endif
#ifdef AUTOPID
myPID.setBangBang(ECRART_V_STOP);
myPID.setTimeStep(PID_TimeStep);
#endif
#ifdef DEBUG // si DEBUG activé
Log.notice(F("FIN DE SETUP" CR));
debug();
#endif
#ifdef DEBUG_CONST
Log.notice(F("CONST OUT SET ON" CR));
const_out_L_state = true;
#endif
}
// *******************************************************************************************************
// ****************************************** boucle principale ******************************************
// *******************************************************************************************************
void loop()
{
#ifdef DEBUG // si DEBUG activé
if (last_time >= interval_loop + millis()) // si intervalle de boucle atteint
{
Serial.print(".");
Serial.print(debug_count);
debug_count++;
debug();
last_time = millis(); // remise à zéro du compteur de temps
}
#endif
bouton_set(); // lecture et controle des boutons
// *******************************************************************************************************
// ********************************* boucle de lecture des potentiomètres ********************************
// *******************************************************************************************************
for (int i = 0; i <= 3; i++)
{
lecture_pot(i); // lecture analogique potentiomètre avec mise à jour du flag de changement de potentiomètre
if (state_pot_change[i] == true) // si changement de position d'un potentiomètre
{
valeurs_set(); // controle des valeurs et des relais
}
// *******************************************************************************************************
// ********************************* boucle de controle des moteurs **************************************
// *******************************************************************************************************
if (stereo_link_state == true || const_out_L_state == true || const_out_R_state == true) // si un des boutons est enfoncé
{
if (motor_change[i] != state_pot_change[i] && last_change_time + bounce_time_pot >= millis()) // si pas changement de position du moteur en cours et temps depuis changement de position potentiomètre supérieur au temps de rebond
{
#ifdef DEBUG_LOOP // si DEBUG activé
Log.warning(F("*** moteur %d nedd to go ***" CR), i);
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
Log.notice(F("state_pot_change[%d] = %d" CR), i, state_pot_change[i]);
Log.notice(F("bounce_time_pot = %d" CR), bounce_time_pot);
Log.notice(F("last_change_time = %d" CR), last_change_time);
Log.notice(F("last_change_time + bounce_time_pot = %d" CR), last_change_time + bounce_time_pot);
Log.notice(F(" millis() = %d" CR), millis());
#endif
lecture_pot(i); // lecture analogique potentiomètre
if (motor_change[0] != true && motor_change[1] != true && motor_change[2] != true && motor_change[3] != true)
{
consigne_set(); // controle des consignes avec controle des valeurs et des relais
}
}
if (motor_change[i] == true) // si changement de position du moteur en cours
{
#ifdef DEBUG_CONST // si DEBUG activé
if (count_motor == true)
{
Log.warning(F("*** changement de position du moteur %d ***" CR), i);
// pidcontroller.start();
}
#endif
moteur_set(i); // controle des moteurs
}
}
// *******************************************************************************************************
// ********************************* boucle de controle des boutons **************************************
// *******************************************************************************************************
if (state_button_change == true) // si changement d'état d'un bouton
{
#ifdef DEBUG_LOOP // si DEBUG activé
Log.warning(F(CR "*** changement de bouton ***" CR));
#endif
diff_set(); // entregistrement des différences de gain et de volume
state_button_change = false; // remise à zéro du flag de changement de bouton
}
// *******************************************************************************************************
// ********************************* boucle de sauvegarde des potentiomètre ******************************
// *******************************************************************************************************
save_pot(i); // sauvegarde position potentiomètre
}
}
+236
View File
@@ -0,0 +1,236 @@
// *******************************************************************************************************
// ****************************************** gestion moteur *********************************************
// *******************************************************************************************************
#include <SparkFunMiniMoto.h> // Include the MiniMoto library
// Create MiniMoto instances, pour controle des moteur en I2C (DRV8830)
MiniMoto motor[4] = {gain_0_motor, vol_0_motor, gain_1_motor, vol_1_motor};
/*In this section we have defined the gain values for the
proportional,integral, and derivative controller i have set
the gain values with the help of trial and error methods.
*/
#define ECRART_V_STOP 5 // hystérésie de positionnement potentiomètre
#define PID
// #define AUTOPID
#ifdef PID
#include "QuickPID.h"
// Define the aggressive and conservative and POn Tuning Parameters
float aggKp = 2, aggKi = 0.5, aggKd = 0.5;
float consKp = 1, consKi = 0.05, consKd = 0.25;
#define ECRART_V_STOP 5 // hystérésie de positionnement potentiomètre
#define pid_windup 10
#define pid_limit_min 6
#define pid_limit_max 63
#define pid_bias 255.0
#define pid_time_step 1000
#define gap_setpoint 25
float pid_input, pid_output, pid_setpoint;
QuickPID myPID(&pid_input, &pid_output, &pid_setpoint);
#endif
#ifdef AUTOPID
#include <AutoPID.h>
// pid settings and gains
#define PID_TimeStep 250 // set PID update interval to 4000ms
#define OUTPUT_MIN 100
#define OUTPUT_MAX 1000
#define KP .12
#define KI .0003
#define KD 0
double motor_read, motor_set, out_speed_value;
AutoPID myPID(&motor_read, &motor_set, &out_speed_value, OUTPUT_MIN, OUTPUT_MAX, KP, KI, KD);
#endif
void moteur_set(int i);
void moteur_stop(int i);
void pid_set(int i);
void pid_set(int i)
{
// #define anal_read
#ifdef anal_read
switch (i)
{
case 0:
pid_input = analogRead(gain_0_pot);
break;
case 1:
pid_input = analogRead(vol_0_pot);
break;
case 2:
pid_input = analogRead(gain_1_pot);
break;
case 3:
pid_input = analogRead(vol_1_pot);
break;
default:
break;
}
#endif
#ifndef anal_read
lecture_pot(i);
pid_input = float(position_lue[i]);
#endif
pid_setpoint = float(position_set[i]);
float gap = abs(pid_setpoint - pid_input); // distance away from setpoint
#ifdef DEBUG_CONST // si DEBUG activé
Log.notice(F("IIIIII = %d" CR), i);
Log.notice(F("gap motor = %d" CR), gap);
Log.notice(F("pid_setpoint = %d" CR), pid_setpoint);
Log.notice(F("pid_input = %d" CR), pid_input);
Log.notice(F("abs(pid_setpoint - pid_input) %d" CR), abs(pid_setpoint - pid_input));
#endif
if (gap < gap_setpoint)
{ // we're close to setpoint, use conservative tuning parameters
myPID.SetTunings(consKp, consKi, consKd);
}
else
{
// we're far from setpoint, use aggressive tuning parameters
myPID.SetTunings(aggKp, aggKi, aggKd);
}
myPID.Compute(); // Let the PID compute the value, returns the calculated optimal output
}
void moteur_stop(int i)
{
#ifdef AUTOPID
myPID.stop();
#endif
#ifdef PID
// myPID.stop();
myPID.SetMode(myPID.Control::manual);
#endif
motor[i].stop(); // stop moteur
delay(50); // attente 50ms
lecture_pot(i); // lecture analogique du potentiomètre
save_pot(i); // sauvegarde position potentiomètre
motor_change[i] = false; // remise à zéro du flag de changement de position du potentiomètre
position_set[i] = position_lue[i]; // remise à zéro de la consigne de position du potentiomètre
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
#ifdef DEBUG_CONST // si DEBUG activé
Log.notice(F("========================== void moteur_stop(%d) ===================================" CR), i);
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
Log.notice(F("position_save[%d] = %d" CR), i, position_save[i]);
Log.notice(F("state_pot_change[%d] = %d" CR), i, state_pot_change[i]);
count_motor = true; // remise à zéro du compteur de boucle
#endif
}
void moteur_set(int i) // fonction de gestion des moteurs
{
#ifdef PID
myPID.SetMode(myPID.Control::automatic);
pid_set(i);
int motor_speed_value = pid_output; // Let the PID compute the value, returns the calculated optimal output
#endif
#ifdef AUTOPID
motor_read = position_lue[i]; // The "goal" the PID controller tries to "reach",
motor_set = position_set[i]; // The "goal" the PID controller tries to "reach",
myPID.run(); // Let the PID compute the value, returns the calculated optimal output
int motor_speed_value = (int)out_speed_value;
int map_speed_value = map(motor_speed_value, 100, 1000, -63, 63);
int const_speed_value = constrain(motor_speed_value, -63, 63);
#endif
#ifdef DEBUG_CONST // si DEBUG activé
if (count_motor == true)
{
Log.notice(F("========================= void moteur_set(%d)" CR), i);
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
Log.notice(F("position_save[%d] = %d" CR), i, position_save[i]); // position sauvegardée
Log.notice(F("motor_speed_value = %d" CR), motor_speed_value); // valeur de vitesse moteur
#ifdef AUTOPID
Log.notice(F("out_speed_value = %d" CR), out_speed_value);
Log.notice(F("(int) out_speed_value = %d" CR), (int)out_speed_value);
Log.notice(F("map_speed_value = %d" CR), map_speed_value);
Log.notice(F("const_speed_value = %d" CR), const_speed_value);
#endif
}
#endif
#ifdef DEBUG_MOTEUR_HARD // si DEBUG activé
Log.notice(F("========================= void moteur_set(%d)" CR), i);
Log.notice(F("position_lue[%d] = %d" CR), i, position_lue[i]);
Log.notice(F("position_set[%d] = %d" CR), i, position_set[i]);
Log.notice(F("motor_change[%d] = %d" CR), i, motor_change[i]);
Log.notice(F("position_save[%d] = %d" CR), i, position_save[i]);
Log.notice(F("motor_speed_value = %d" CR), motor_speed_value);
#ifdef AUTOPID
Log.notice(F("out_speed_value = %d" CR), out_speed_value);
Log.notice(F("(int) out_speed_value = %d" CR), (int)out_speed_value);
Log.notice(F("map_speed_value = %d" CR), map_speed_value);
Log.notice(F("const_speed_value = %d" CR), const_speed_value);
#endif
#endif
if (position_lue[i] == position_set[i] || position_set[i] > 1023 || position_set[i] < 0) // si position lue égale à la consigne ou consigne hors bornes
{
#ifdef DEBUG_MOTEUR // si DEBUG activé
Log.notice(F("MOTEUR[%d] OK" CR), i);
#endif
#ifdef DEBUG_CONST // si DEBUG activé
count_motor = true;
#endif
moteur_stop(i);
return;
}
else if (position_lue[i] < (position_set[i] + ECRART_V_STOP) && position_lue[i] > (position_set[i] - ECRART_V_STOP)) // si moteur entre consigne et ECRART_V_STOP
{
#ifdef DEBUG_MOTEUR // si DEBUG activé
Log.notice(F("MOTEUR[%d] OK" CR), i);
#endif
#ifdef DEBUG_CONST // si DEBUG activé
count_motor = true;
#endif
moteur_stop(i);
return;
}
// *******************************************************************************************************
// si moteur doit aller vers la gauche
else if (position_lue[i] > (position_set[i] + (ECRART_V_STOP / 2))) // si moteur n'est pas entre consigne et ECRART_V_STOP
{
#ifdef DEBUG_CONST // si DEBUG activé
if (count_motor == true)
{
Log.notice(F("========================== MOTEUR[%d] GO RIGHT at speed = %d ============================" CR), i, motor_speed_value);
count_motor = false;
}
#endif
motor_change[i] = true;
motor[i].drive(-motor_speed_value);
}
else if (position_lue[i] < (position_set[i] - (ECRART_V_STOP / 2))) // si moteur n'est pas entre consigne et ECRART_V_STOP
{
#ifdef DEBUG_CONST // si DEBUG activé
if (count_motor == true)
{
Log.notice(F("========================== MOTEUR[%d] GO LEFT at speed = %d ============================" CR), i, motor_speed_value);
count_motor = false;
}
#endif
motor_change[i] = true;
motor[i].drive(motor_speed_value);
}
else
{
#ifdef DEBUG_MOTEUR // si DEBUG activé
Log.notice(F("MOTEUR[%d] NOK" CR), i);
#endif
#ifdef DEBUG_CONST // si DEBUG activé
count_motor = true;
#endif
motor[i].brake(); // stop moteur
moteur_stop(i);
return;
}
}
+14
View File
@@ -0,0 +1,14 @@
/*
Faire un calcul de consigne pour toujours avoir un écart définit entre les deux potar
faire PID avec analogRead pour voir si plus réactif
pour avoir les valeur de PID faire un code de test pour connaitre les valeurs
Set PID value :
Le PID semble mal fonctionner car le temps de boucle est trop long pour qu'il puisse faire correctement son calcul
#define __Kp 260 // Proportional constant
#define __Ki 2.7 // Integral Constant
#define __Kd 2000 // Derivative Constant
*/
+121
View File
@@ -0,0 +1,121 @@
#include <ResponsiveAnalogRead.h>
// make a ResponsiveAnalogRead object, pass in the pin, and either true or false depending on if you want sleep enabled
// enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly,
// where as disabling sleep will cause values to ease into their correct position smoothly and with slightly greater accuracy
// the next optional argument is snapMultiplier, which is set to 0.01 by default
// you can pass it a value from 0 to 1 that controls the amount of easing
// increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive
// but doing so may cause more noise to seep through if sleep is not enabled
#define amount_easing 0.05 // valeur d'atténuation du potentiomètre
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);
#define max_pot 1005 // valeur max potentiomètre pour calibrage ADC
#define min_pot 0 // valeur min potentiomètre pour calibrage ADC
void lecture_pot(int i); // lecture analogique potentiomètre
void save_pot(int i); // sauvegarde position potentiomètre
// *******************************************************************************************************
// ****************************************** lecture bouton *********************************************
// *******************************************************************************************************
void lecture_pot(int i)
{
switch (i)
{
case 0:
#ifdef ENABLE_LEFT // si DEBUG LEFT activé bouton droit ignoré
gain_0.update();
if (gain_0.hasChanged())
{
state_pot_change[i] = true; // il y a changement de position du potentiomètre
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
position_lue[i] = gain_0.getValue();
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
position_lue[i] = constrain(position_lue[i], 0, max_pot);
}
#else
position_lue[0] = 512;
position_set[i] = 512;
#endif
break;
case 1:
#ifdef ENABLE_LEFT // si DEBUG LEFT activé bouton droit ignoré
vol_0.update();
if (vol_0.hasChanged())
{
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
state_pot_change[i] = true; // il y a changement de position du potentiomètre
position_lue[i] = vol_0.getValue();
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
position_lue[i] = constrain(position_lue[i], 0, 1023);
}
#else
position_lue[i] = 512;
position_set[i] = 512;
#endif
break;
case 2:
#ifdef ENABLE_RIGHT // si DEBUG RIGHT activé bouton gauche ignoré
gain_1.update();
if (gain_1.hasChanged())
{
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
state_pot_change[i] = true; // il y a changement de position du potentiomètre
position_lue[i] = gain_1.getValue();
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
position_lue[i] = constrain(position_lue[i], 0, 1023);
}
#else
position_lue[i] = 512;
position_set[i] = 512;
#endif
break;
case 3:
#ifdef ENABLE_RIGHT // si DEBUG RIGHT activé bouton gauche ignoré
vol_1.update();
if (vol_1.hasChanged())
{
last_change_time = millis(); // sauvegarde du temps du dernier changement de position
state_pot_change[i] = true; // il y a changement de position du potentiomètre
position_lue[i] = vol_1.getValue();
position_lue[i] = map(position_lue[i], max_pot, min_pot, 0, 1023);
position_lue[i] = constrain(position_lue[i], 0, 1023);
}
#else
position_lue[i] = 512;
position_set[i] = 512;
#endif
break;
}
#ifdef DEBUG_POT // si DEBUG activé
if (state_pot_change[i] == true)
{
Log.notice(F("il y a changement de potentiomètre dans lecture pot %d" CR), i);
Log.trace("position_lue[%d] = %d" CR, i, position_lue[i]);
Log.trace("position_save[%d] = %d" CR, i, position_save[i]);
}
#endif
}
void save_pot(int i)
{
#ifdef DEBUG_POT // si DEBUG activé
if (state_pot_change[i] == true)
{
Log.notice(F("======= void save_pot(%d)" CR), i);
}
#endif
position_save[i] = position_lue[i]; // sauvegarde position potentiomètre
if (last_change_time + bounce_time_pot >= millis())
{
state_pot_change[i] = false; // RAZ flag de changement de position du potentiomètre
}
// last_change_time = millis(); // sauvegarde du temps du dernier changement de position
}
+126
View File
@@ -0,0 +1,126 @@
// *******************************************************************************************************
// ****************************************** gestion relais *********************************************
// *******************************************************************************************************
#include "PCF8574.h" // https://github.com/RobTillaart/PCF8574/blob/master/examples/PCF8574_test1/PCF8574_test1.ino
// instance carte relais
PCF8574 PCF_vol_0(vol_0_relais);
PCF8574 PCF_gain_0(gain_0_relais);
PCF8574 PCF_vol_1(vol_1_relais);
PCF8574 PCF_gain_1(gain_1_relais);
#define delay_relais 1 // délai entre chaque relais
void relais_set(int relais);
void relais_send(int relais, int value, int byte_value);
void relais_send(int relais, int value, int byte_value) // fonction d'envoie de valeur sur relais
{
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("relais_send(%d, %d, %d)" CR, relais, value, byte_value);
#endif
// PCF.write(const uint8_t pin, const uint8_t value) writes a single pin; pin = 0..7; value is HIGH(1) or LOW (0)
// uint8_t write(const uint8_t value) writes all pins; value = 0..255
switch (relais)
{
case 0:
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("PCF_gain_0.write(%d, %d)" CR, byte_value, value);
#endif
PCF_gain_0.write(byte_value, value); // envoie valeur sur relais volume gauche
break;
case 1:
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("PCF_vol_0.write(%d, %d)" CR, byte_value, value);
#endif
PCF_vol_0.write(byte_value, value); // envoie valeur sur relais gain gauche
break;
case 2:
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("PCF_gain_1.write(%d, %d)" CR, byte_value, value);
#endif
PCF_gain_1.write(byte_value, value); // envoie valeur sur relais volume droite
break;
case 3:
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("PCF_vol_1.write(%d, %d)" CR, byte_value, value);
#endif
PCF_vol_1.write(byte_value, value); // envoie valeur sur relais gain droite
break;
}
delay(delay_relais);
}
void relais_set(int relais) // fonction de gestion des relais
{
// tableau de valeur des relais
switch (relais)
{
case 0:
relais_map[0] = relais_gain_val[0];
break;
case 1:
relais_map[1] = relais_vol_val[0];
break;
case 2:
relais_map[2] = relais_gain_val[1];
break;
case 3:
relais_map[3] = relais_vol_val[1];
break;
}
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("relais_map[%d] = %d" CR, relais, relais_map[relais]);
Log.notice("relais_old[%d] = %d" CR, relais, relais_old[relais]);
#endif
if (relais_map[relais] != relais_old[relais]) // si changement de valeur
{
// si changement en sens montant
if (relais_map[relais] < relais_old[relais])
{
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("relais UP" CR);
Log.notice("relais_map[%d] = %d" CR, relais, relais_map[relais]);
Log.notice("relais_old[%d] = %d" CR, relais, relais_old[relais]);
#endif
for (int j = 0; j <= 7; j++)
{
if (bitRead(relais_map[relais], j) == 1)
{
relais_send(relais, 1, j);
}
else if (bitRead(relais_map[relais], j) == 0)
{
relais_send(relais, 0, j);
}
}
}
// si changement en sens descendant
if (relais_map[relais] > relais_old[relais])
{
#ifdef DEBUG_RELAIS // si DEBUG activé
Log.notice("relais DOWN" CR);
Log.notice("relais_map[%d] = %d" CR, relais, relais_map[relais]);
Log.notice("relais_old[%d] = %d" CR, relais, relais_old[relais]);
#endif
for (int j = 7; j >= 0; j--)
{
if (bitRead(relais_map[relais], j) == 1)
{
relais_send(relais, 1, j);
}
else if (bitRead(relais_map[relais], j) == 0)
{
relais_send(relais, 0, j);
}
}
}
relais_old[relais] = relais_map[relais]; // sauvegarde valeur
}
}
+26
View File
@@ -0,0 +1,26 @@
void anticlikgain() {
newvaluegain = gaincomensatedroot;
if (newvaluegain < actualvaluegain) {
for (int i = 7; i <= 0; i--) { // mise à jout des bits sens montée
bitWrite(I2Csendgain, i, bitRead(newvaluegain, i));
I2cgain(); // envoi I2C
delay(delaytime);
}
actualvaluegain = newvaluegain;
I2Csendgain = actualvaluegain;
}
// sens inverse
if (newvaluegain > actualvaluegain) {
I2Csendgain = actualvaluegain;
for (int i = 0; i < 7; i--) { // mise à jout des bits sens montée
bitWrite(I2Csendgain, i, bitRead(newvaluegain, i));
I2cgain(); // envoi I2C
delay(delaytime);
actualvaluegain = newvaluegain;
}
}
}
+31
View File
@@ -0,0 +1,31 @@
void anticlikvol() {
if (switchread == 1) {
newvalue = smooth;
}
if (switchread == 0) {
newvalue = smoothgainmap - difference;
newvalue = constrain(newvalue, 0, 255);
}
if (newvalue > actualvalue) { // sens montée
I2Csend = actualvalue;
actualvalue = newvalue;
for (int i = 7; i <= 0; i--) { // mise à jout des bits sens montée
bitWrite(I2Csend, i, bitRead(newvalue, i));
I2c(); // envoi I2C
delay(delaytime);
}
}
if (newvalue < actualvalue) { // sens descente
I2Csend = actualvalue;
actualvalue = newvalue;
for (int i = 0; i < 7; i++) { // mise à jout des bits sens descente
bitWrite(I2Csend, i, bitRead(newvalue, i));
I2c(); // envoi I2C
delay(delaytime);
}
}
}
@@ -0,0 +1,14 @@
void I2cgain() {
// transmition I2C vers relais
Wire.beginTransmission(0x21); //33 dec // transmit to device #9 A2L A1L A0H gain
Wire.write(I2Csendgain);
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(0x39); // 57 dec // transmit to device #9 A2L A1L A0H gain
Wire.write(I2Csendgain);
Wire.endTransmission(); // stop transmitting
}
+14
View File
@@ -0,0 +1,14 @@
void I2c() {
// transmition I2C vers relais
Wire.beginTransmission(0x20); //32 dec // transmit to device #8 A2L A1L A0L volume
Wire.write(I2Csend);
Wire.endTransmission(); // stop transmitting
Wire.beginTransmission(0x38); //56 dec // transmit to device #8 A2L A1L A0L volume
Wire.write(I2Csend);
Wire.endTransmission(); // stop transmitting
}
+7
View File
@@ -0,0 +1,7 @@
void vol_pot() {
if (switchread == 1) {
smooth = byte(vol_1.getValue() / 4) - 1; // passage de 9 a 48 bits et attention version inversée, fonctionne comme un potentiometre "normal" ~
}
}
+5
View File
@@ -0,0 +1,5 @@
void gain_pot() {
smoothgain = byte(gain_1.getValue() / 4); // passage de 9 a 48 bits et attention version inversée, fonctionne comme un potentiometre "normal" ~
}
+226
View File
@@ -0,0 +1,226 @@
void mapgain() {
// gaincomensatedroot=smoothgainmap;
smoothgainmap = map(smoothgain, 0, 255, 0, 156); // 156
if (smoothgainmap <= 7 && smoothgainmap >= 0) {
gaincomensatedroot = smoothgainmap;
}
if (smoothgainmap <= 14 && smoothgainmap >= 8) {
gaincomensatedroot = smoothgainmap + 1;
}
if (smoothgainmap <= 18 && smoothgainmap >= 15) {
gaincomensatedroot = smoothgainmap + 3; //+4
}
if (smoothgainmap == 19) {
gaincomensatedroot = smoothgainmap + 4;
}
if (smoothgainmap <= 23 && smoothgainmap >= 20) {
gaincomensatedroot = smoothgainmap + 5;
}
if (smoothgainmap <= 25 && smoothgainmap >= 24) {
gaincomensatedroot = smoothgainmap + 6;
}
if (smoothgainmap <= 28 && smoothgainmap >= 26) {
gaincomensatedroot = smoothgainmap + 7;
}
if (smoothgainmap <= 31 && smoothgainmap >= 29) {
gaincomensatedroot = smoothgainmap + 8;
}
if (smoothgainmap <= 35 && smoothgainmap >= 32) {
gaincomensatedroot = smoothgainmap + 9;
}
if (smoothgainmap <= 37 && smoothgainmap >= 36) {
gaincomensatedroot = smoothgainmap + 10;
}
if (smoothgainmap == 38) {
gaincomensatedroot = smoothgainmap + 11;
}
if (smoothgainmap <= 40 && smoothgainmap >= 39) {
gaincomensatedroot = smoothgainmap + 12;
}
if (smoothgainmap <= 42 && smoothgainmap >= 41) {
gaincomensatedroot = smoothgainmap + 13;
}
if (smoothgainmap <= 44 && smoothgainmap >= 43) {
gaincomensatedroot = smoothgainmap + 14;
}
if (smoothgainmap <= 46 && smoothgainmap >= 45) {
gaincomensatedroot = smoothgainmap + 15;
}
if (smoothgainmap == 47) {
gaincomensatedroot = smoothgainmap + 16;
}
if (smoothgainmap <= 58 && smoothgainmap >= 48) {
gaincomensatedroot = smoothgainmap + 18;
}
if (smoothgainmap <= 60 && smoothgainmap >= 59) {
gaincomensatedroot = smoothgainmap + 18;
}
if (smoothgainmap <= 63 && smoothgainmap >= 61) {
gaincomensatedroot = smoothgainmap + 19;
}
if (smoothgainmap <= 66 && smoothgainmap >= 64) {
gaincomensatedroot = smoothgainmap + 20;
}
if (smoothgainmap <= 68 && smoothgainmap >= 67) {
gaincomensatedroot = smoothgainmap + 21;
}
if (smoothgainmap <= 70 && smoothgainmap >= 69) {
gaincomensatedroot = smoothgainmap + 22;
}
if (smoothgainmap <= 72 && smoothgainmap >= 71) {
gaincomensatedroot = smoothgainmap + 23;
}
if (smoothgainmap <= 74 && smoothgainmap >= 73) {
gaincomensatedroot = smoothgainmap + 24;
}
if (smoothgainmap <= 76 && smoothgainmap >= 75) {
gaincomensatedroot = smoothgainmap + 25;
}
if (smoothgainmap <= 78 && smoothgainmap >= 77) {
gaincomensatedroot = smoothgainmap + 26;
}
if (smoothgainmap <= 80 && smoothgainmap >= 79) {
gaincomensatedroot = smoothgainmap + 27;
}
if (smoothgainmap == 81) {
gaincomensatedroot = smoothgainmap + 28;
}
if (smoothgainmap == 82) {
gaincomensatedroot = smoothgainmap + 29;
}
if (smoothgainmap <= 84 && smoothgainmap >= 83) {
gaincomensatedroot = smoothgainmap + 30;
}
if (smoothgainmap <= 86 && smoothgainmap >= 85) {
gaincomensatedroot = smoothgainmap + 31;
}
if (smoothgainmap == 87) {
gaincomensatedroot = smoothgainmap + 32;
}
if (smoothgainmap == 88) {
gaincomensatedroot = smoothgainmap + 33;
}
if (smoothgainmap <= 90 && smoothgainmap >= 89) {
gaincomensatedroot = smoothgainmap + 34;
}
if (smoothgainmap <= 104 && smoothgainmap >= 91) {
gaincomensatedroot = smoothgainmap + 35;
}
if (smoothgainmap <= 107 && smoothgainmap >= 105) {
gaincomensatedroot = smoothgainmap + 36;
}
if (smoothgainmap <= 110 && smoothgainmap >= 108) {
gaincomensatedroot = smoothgainmap + 37;
}
if (smoothgainmap <= 113 && smoothgainmap >= 111) {
gaincomensatedroot = smoothgainmap + 38;
}
if (smoothgainmap <= 115 && smoothgainmap >= 114) {
gaincomensatedroot = smoothgainmap + 39;
}
if (smoothgainmap <= 118 && smoothgainmap >= 116) {
gaincomensatedroot = smoothgainmap + 40;
}
if (smoothgainmap == 119) {
gaincomensatedroot = smoothgainmap + 42;
}
if (smoothgainmap <= 121 && smoothgainmap >= 120) {
gaincomensatedroot = smoothgainmap + 43;
}
if (smoothgainmap == 122) {
gaincomensatedroot = smoothgainmap + 44;
}
if (smoothgainmap <= 124 && smoothgainmap >= 123) {
gaincomensatedroot = smoothgainmap + 45;
}
if (smoothgainmap <= 126 && smoothgainmap >= 125) {
gaincomensatedroot = smoothgainmap + 46;
}
if (smoothgainmap <= 128 && smoothgainmap >= 127) {
gaincomensatedroot = smoothgainmap + 47;
}
if (smoothgainmap == 129) {
gaincomensatedroot = smoothgainmap + 48;
}
if (smoothgainmap == 130) {
gaincomensatedroot = smoothgainmap + 49;
}
if (smoothgainmap == 131) {
gaincomensatedroot = smoothgainmap + 50;
}
if (smoothgainmap == 132) {
gaincomensatedroot = smoothgainmap + 51;
}
if (smoothgainmap <= 134 && smoothgainmap >= 133) {
gaincomensatedroot = smoothgainmap + 52;
}
if (smoothgainmap == 135) {
gaincomensatedroot = smoothgainmap + 53;
}
if (smoothgainmap == 136) {
gaincomensatedroot = smoothgainmap + 54;
}
if (smoothgainmap == 137) {
gaincomensatedroot = smoothgainmap + 60;
}
if (smoothgainmap == 138) {
gaincomensatedroot = smoothgainmap + 61;
}
if (smoothgainmap == 139) {
gaincomensatedroot = smoothgainmap + 63;
}
if (smoothgainmap == 140) {
gaincomensatedroot = smoothgainmap + 64;
}
if (smoothgainmap == 141) {
gaincomensatedroot = smoothgainmap + 64;
}
if (smoothgainmap == 142) {
gaincomensatedroot = smoothgainmap + 64;
}
if (smoothgainmap == 143) {
gaincomensatedroot = smoothgainmap + 65;
}
if (smoothgainmap == 144) {
gaincomensatedroot = smoothgainmap + 68;
}
if (smoothgainmap == 145) {
gaincomensatedroot = smoothgainmap + 70;
}
if (smoothgainmap == 146) {
gaincomensatedroot = smoothgainmap + 71;
}
if (smoothgainmap == 147) {
gaincomensatedroot = smoothgainmap + 73;
}
if (smoothgainmap == 148) {
gaincomensatedroot = smoothgainmap + 75;
}
if (smoothgainmap == 149) {
gaincomensatedroot = smoothgainmap + 78;
}
if (smoothgainmap == 150) {
gaincomensatedroot = smoothgainmap + 80;
}
if (smoothgainmap == 151) {
gaincomensatedroot = smoothgainmap + 83;
}
if (smoothgainmap == 152) {
gaincomensatedroot = smoothgainmap + 84;
}
if (smoothgainmap == 153) {
gaincomensatedroot = smoothgainmap + 87;
}
if (smoothgainmap == 154) {
gaincomensatedroot = smoothgainmap + 92;
}
if (smoothgainmap == 155) {
gaincomensatedroot = smoothgainmap + 95;
}
if (smoothgainmap == 156) {
gaincomensatedroot = smoothgainmap + 99;
}
}
@@ -0,0 +1,82 @@
// relay card
#include <Wire.h> // lib pour gestion I2C
#include <ResponsiveAnalogRead.h>
#include <SparkFunMiniMoto.h> // Include the MiniMoto library
// Create two MiniMoto instances, with different address settings.
MiniMoto motor0(0xCE); // A1 = 1, A0 = clear
MiniMoto motor1(0xD0); // A1 = 1, A0 = 1 (default)
#define vol_pot_1 A0
#define gain_pot_1 A1
#define vol_pot_2 A2
#define gain_pot_2 A3
#define const_out_sw 2 // = switchApin
ResponsiveAnalogRead vol_1(vol_pot_1, true);
ResponsiveAnalogRead gain_1(gain_pot_1, true);
ResponsiveAnalogRead vol_2(vol_pot_2, true);
ResponsiveAnalogRead gain_2(gain_pot_2, true);
//ResponsiveAnalogRead analog2(gainpin, true);
byte level = 0; // info qu'on envoi en I2C pour l'attenuateur relais
float pot1value = 0; // valeur position du potentiometre principal
const int potprincipal = A0; // pinuche pour la mesure de position du potentiometre principal sur le nano : A2
int difference = 0; // difference entre gain et volume
byte switchread = 1;
byte const_out_value_old = 0;
byte const_out_value = 0;
byte compensation = 0;
byte actualvalue = 127;
byte actualvaluegain = 127;
int newvalue = 0;
byte newvaluegain = 127;
byte smooth = 0;
byte smoothgain = 127;
byte smoothgainmap = 0;
byte gaincomensatedroot = 0;
byte I2Csend = 127;
byte I2Csendgain = 127;
unsigned long delaytime = 1;
// the setup function runs once when you press reset or power the board
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
pinMode(vol_pot_1, INPUT);
pinMode(gain_pot_1, INPUT);
pinMode(vol_pot_2, INPUT);
pinMode(gain_pot_2, INPUT);
pinMode(const_out_sw, INPUT_PULLUP);
Serial.begin(115200);
Serial.setTimeout(5);
delay(100); // give me time to bring up serial monitor
const_out_value_old = digitalRead(const_out_sw);
Serial.println("relay card test");
}
// the loop function runs over and over again forever
void loop() {
// update the ResponsiveAnalogRead object every loop
vol_1.update();
gain_1.update();
vol_2.update();
gain_2.update();
vol_pot(); // lecture du potentiometre volume
gain_pot(); // lecture du potentiometre gain
mapgain (); // mappage du potentiometre de gain
anticlikvol (); // gestion du clik volume
anticlikgain (); // gestion du clik gain
serialmonitoring (); // serial monitoring
switchA (); // lire le switch A
}
+21
View File
@@ -0,0 +1,21 @@
void serialmonitoring() {
// gestion ecriture dans variable
while (Serial.available()) { // parametrage pour envoi de commandes par le monitor serie
smoothgainmap = Serial.readString().toDouble();
}
//
Serial.print("smoothgainmap=");
Serial.print(smoothgainmap);
Serial.print(" newvalue=");
Serial.print(newvalue);
Serial.print(" smooth=");
Serial.print(smooth);
Serial.print(" difference=");
Serial.println(difference);
}
+12
View File
@@ -0,0 +1,12 @@
void switchA() {
switchread = digitalRead(switchApin);
newvalueswA = switchread;
if (newvalueswA != oldvalueswA) {
// smooth= byte (~analog1.getValue()/4)-1; // passage de 9 a 48 bits et attention version inversée, fonctionne comme un potentiometre "normal" ~
// smooth= gaincomensatedroot - difference;
difference = smoothgainmap - smooth;
oldvalueswA = newvalueswA;
}
}
+393
View File
@@ -0,0 +1,393 @@
// *******************************************************************************************************
// ****************************************** gestion valeurs ********************************************
// *******************************************************************************************************
void valeurs_set(int i); // gestion des valeurs
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()
{
#ifdef DEBUG_VALEURS // si DEBUG activé
Log.notice(F("*** valeurs_set ***" CR));
#endif
if (state_pot_change[0] == true && position_lue[0] != position_save[0]) // si changement d'état du potentiomètre de gain gauche
{
smoothgain[0] = byte(position_lue[0] / 4);
position_change[0] = true; // il y a changement de position du potentiomètre de gain gauche
smoothgain_set(0); // mise à jour de valeur du relais gain gauche
#ifdef DEBUG_VALEURS
Log.notice(F("changement pot gain gauche" CR));
Log.trace(F("smoothgain[0] = %d" CR), smoothgain[0]);
Log.trace(F("relais_gain_val[0] = %d" CR), relais_gain_val[0]);
#endif
}
if (state_pot_change[1] == true && position_lue[1] != position_save[1]) // si changement d'état du potentiomètre de volume gauche
{
smoothvol[0] = byte(position_lue[1] / 4) - 1; // 156
position_change[1] = true; // il y a changement de position du potentiomètre de volume gauche
smoothvolume_set(0);
#ifdef DEBUG_VALEURS
Log.notice(F("changement pot volume gauche" CR));
Log.trace(F("smoothvol[0] = %d" CR), smoothvol[0]);
Log.trace(F("relais_vol_val[0] = %d" CR), relais_vol_val[0]);
#endif
}
if (state_pot_change[2] == true && position_lue[2] != position_save[2]) // si changement d'état du potentiomètre de gain droit
{
smoothgain[1] = byte(position_lue[2] / 4); // 156
position_change[2] = true; // il y a changement de position du potentiomètre de gain droitf
smoothgain_set(1); // mise à jour de valeur du relais gain droit
#ifdef DEBUG_VALEURS
Log.notice(F("changement pot gain droit" CR));
Log.trace(F("smoothgain[1] = %d" CR), smoothgain[1]);
Log.trace(F("relais_gain_val[1] = %d" CR), relais_gain_val[1]);
#endif
}
if (state_pot_change[3] == true && position_lue[3] != position_save[3]) // si changement d'état du potentiomètre de volume droit
{
smoothvol[1] = byte(position_lue[3] / 4) - 1; // 156
position_change[3] = true; // il y a changement de position du potentiomètre de volume droit
smoothvolume_set(1); // mise à jour de valeur du relais volume droit
#ifdef DEBUG_VALEURS
Log.notice(F("changement pot volume droit" CR));
Log.trace(F("smoothvol[1] = %d" CR), smoothvol[1]);
Log.trace(F("relais_vol_val[1] = %d" CR), relais_vol_val[1]);
#endif
}
}
void smoothgain_set(int i)
{
// lisages manuel des valeurs de gain
smoothgain[i] = map(smoothgain[i], 0, 255, 0, 156); // 156sm
{
relais_gain_val[i] = smoothgain[i];
}
if (smoothgain[i] <= 7 && smoothgain[i] >= 0)
{
relais_gain_val[i] = smoothgain[i];
}
if (smoothgain[i] <= 14 && smoothgain[i] >= 8)
{
relais_gain_val[i] = smoothgain[i] + 1;
}
if (smoothgain[i] <= 18 && smoothgain[i] >= 15)
{
relais_gain_val[i] = smoothgain[i] + 3; //+4
}
if (smoothgain[i] == 19)
{
relais_gain_val[i] = smoothgain[i] + 4;
}
if (smoothgain[i] <= 23 && smoothgain[i] >= 20)
{
relais_gain_val[i] = smoothgain[i] + 5;
}
if (smoothgain[i] <= 25 && smoothgain[i] >= 24)
{
relais_gain_val[i] = smoothgain[i] + 6;
}
if (smoothgain[i] <= 28 && smoothgain[i] >= 26)
{
relais_gain_val[i] = smoothgain[i] + 7;
}
if (smoothgain[i] <= 31 && smoothgain[i] >= 29)
{
relais_gain_val[i] = smoothgain[i] + 8;
}
if (smoothgain[i] <= 35 && smoothgain[i] >= 32)
{
relais_gain_val[i] = smoothgain[i] + 9;
}
if (smoothgain[i] <= 37 && smoothgain[i] >= 36)
{
relais_gain_val[i] = smoothgain[i] + 10;
}
if (smoothgain[i] == 38)
{
relais_gain_val[i] = smoothgain[i] + 11;
}
if (smoothgain[i] <= 40 && smoothgain[i] >= 39)
{
relais_gain_val[i] = smoothgain[i] + 12;
}
if (smoothgain[i] <= 42 && smoothgain[i] >= 41)
{
relais_gain_val[i] = smoothgain[i] + 13;
}
if (smoothgain[i] <= 44 && smoothgain[i] >= 43)
{
relais_gain_val[i] = smoothgain[i] + 14;
}
if (smoothgain[i] <= 46 && smoothgain[i] >= 45)
{
relais_gain_val[i] = smoothgain[i] + 15;
}
if (smoothgain[i] == 47)
{
relais_gain_val[i] = smoothgain[i] + 16;
}
if (smoothgain[i] <= 58 && smoothgain[i] >= 48)
{
relais_gain_val[i] = smoothgain[i] + 18;
}
if (smoothgain[i] <= 60 && smoothgain[i] >= 59)
{
relais_gain_val[i] = smoothgain[i] + 18;
}
if (smoothgain[i] <= 63 && smoothgain[i] >= 61)
{
relais_gain_val[i] = smoothgain[i] + 19;
}
if (smoothgain[i] <= 66 && smoothgain[i] >= 64)
{
relais_gain_val[i] = smoothgain[i] + 20;
}
if (smoothgain[i] <= 68 && smoothgain[i] >= 67)
{
relais_gain_val[i] = smoothgain[i] + 21;
}
if (smoothgain[i] <= 70 && smoothgain[i] >= 69)
{
relais_gain_val[i] = smoothgain[i] + 22;
}
if (smoothgain[i] <= 72 && smoothgain[i] >= 71)
{
relais_gain_val[i] = smoothgain[i] + 23;
}
if (smoothgain[i] <= 74 && smoothgain[i] >= 73)
{
relais_gain_val[i] = smoothgain[i] + 24;
}
if (smoothgain[i] <= 76 && smoothgain[i] >= 75)
{
relais_gain_val[i] = smoothgain[i] + 25;
}
if (smoothgain[i] <= 78 && smoothgain[i] >= 77)
{
relais_gain_val[i] = smoothgain[i] + 26;
}
if (smoothgain[i] <= 80 && smoothgain[i] >= 79)
{
relais_gain_val[i] = smoothgain[i] + 27;
}
if (smoothgain[i] == 81)
{
relais_gain_val[i] = smoothgain[i] + 28;
}
if (smoothgain[i] == 82)
{
relais_gain_val[i] = smoothgain[i] + 29;
}
if (smoothgain[i] <= 84 && smoothgain[i] >= 83)
{
relais_gain_val[i] = smoothgain[i] + 30;
}
if (smoothgain[i] <= 86 && smoothgain[i] >= 85)
{
relais_gain_val[i] = smoothgain[i] + 31;
}
if (smoothgain[i] == 87)
{
relais_gain_val[i] = smoothgain[i] + 32;
}
if (smoothgain[i] == 88)
{
relais_gain_val[i] = smoothgain[i] + 33;
}
if (smoothgain[i] <= 90 && smoothgain[i] >= 89)
{
relais_gain_val[i] = smoothgain[i] + 34;
}
if (smoothgain[i] <= 104 && smoothgain[i] >= 91)
{
relais_gain_val[i] = smoothgain[i] + 35;
}
if (smoothgain[i] <= 107 && smoothgain[i] >= 105)
{
relais_gain_val[i] = smoothgain[i] + 36;
}
if (smoothgain[i] <= 110 && smoothgain[i] >= 108)
{
relais_gain_val[i] = smoothgain[i] + 37;
}
if (smoothgain[i] <= 113 && smoothgain[i] >= 111)
{
relais_gain_val[i] = smoothgain[i] + 38;
}
if (smoothgain[i] <= 115 && smoothgain[i] >= 114)
{
relais_gain_val[i] = smoothgain[i] + 39;
}
if (smoothgain[i] <= 118 && smoothgain[i] >= 116)
{
relais_gain_val[i] = smoothgain[i] + 40;
}
if (smoothgain[i] == 119)
{
relais_gain_val[i] = smoothgain[i] + 42;
}
if (smoothgain[i] <= 121 && smoothgain[i] >= 120)
{
relais_gain_val[i] = smoothgain[i] + 43;
}
if (smoothgain[i] == 122)
{
relais_gain_val[i] = smoothgain[i] + 44;
}
if (smoothgain[i] <= 124 && smoothgain[i] >= 123)
{
relais_gain_val[i] = smoothgain[i] + 45;
}
if (smoothgain[i] <= 126 && smoothgain[i] >= 125)
{
relais_gain_val[i] = smoothgain[i] + 46;
}
if (smoothgain[i] <= 128 && smoothgain[i] >= 127)
{
relais_gain_val[i] = smoothgain[i] + 47;
}
if (smoothgain[i] == 129)
{
relais_gain_val[i] = smoothgain[i] + 48;
}
if (smoothgain[i] == 130)
{
relais_gain_val[i] = smoothgain[i] + 49;
}
if (smoothgain[i] == 131)
{
relais_gain_val[i] = smoothgain[i] + 50;
}
if (smoothgain[i] == 132)
{
relais_gain_val[i] = smoothgain[i] + 51;
}
if (smoothgain[i] <= 134 && smoothgain[i] >= 133)
{
relais_gain_val[i] = smoothgain[i] + 52;
}
if (smoothgain[i] == 135)
{
relais_gain_val[i] = smoothgain[i] + 53;
}
if (smoothgain[i] == 136)
{
relais_gain_val[i] = smoothgain[i] + 54;
}
if (smoothgain[i] == 137)
{
relais_gain_val[i] = smoothgain[i] + 60;
}
if (smoothgain[i] == 138)
{
relais_gain_val[i] = smoothgain[i] + 61;
}
if (smoothgain[i] == 139)
{
relais_gain_val[i] = smoothgain[i] + 63;
}
if (smoothgain[i] == 140)
{
relais_gain_val[i] = smoothgain[i] + 64;
}
if (smoothgain[i] == 141)
{
relais_gain_val[i] = smoothgain[i] + 64;
}
if (smoothgain[i] == 142)
{
relais_gain_val[i] = smoothgain[i] + 64;
}
if (smoothgain[i] == 143)
{
relais_gain_val[i] = smoothgain[i] + 65;
}
if (smoothgain[i] == 144)
{
relais_gain_val[i] = smoothgain[i] + 68;
}
if (smoothgain[i] == 145)
{
relais_gain_val[i] = smoothgain[i] + 70;
}
if (smoothgain[i] == 146)
{
relais_gain_val[i] = smoothgain[i] + 71;
}
if (smoothgain[i] == 147)
{
relais_gain_val[i] = smoothgain[i] + 73;
}
if (smoothgain[i] == 148)
{
relais_gain_val[i] = smoothgain[i] + 75;
}
if (smoothgain[i] == 149)
{
relais_gain_val[i] = smoothgain[i] + 78;
}
if (smoothgain[i] == 150)
{
relais_gain_val[i] = smoothgain[i] + 80;
}
if (smoothgain[i] == 151)
{
relais_gain_val[i] = smoothgain[i] + 83;
}
if (smoothgain[i] == 152)
{
relais_gain_val[i] = smoothgain[i] + 84;
}
if (smoothgain[i] == 153)
{
relais_gain_val[i] = smoothgain[i] + 87;
}
if (smoothgain[i] == 154)
{
relais_gain_val[i] = smoothgain[i] + 92;
}
if (smoothgain[i] == 155)
{
relais_gain_val[i] = smoothgain[i] + 95;
}
if (smoothgain[i] == 156)
{
relais_gain_val[i] = smoothgain[i] + 99;
}
#ifdef DEBUG_RELAIS
Log.notice(F(CR "int smoothgain_set()" CR));
Log.trace(F("i = %d" CR), i);
Log.trace(F("relais_gain_val = %d" CR), relais_gain_val[i]);
Log.trace(F("smoothgain = %d" CR), smoothgain[i]);
#endif
if (i == 0)
{
relais_set(0); // mise à jour des relais
}
if (i == 1)
{
relais_set(2); // mise à jour des relais
}
}
void smoothvolume_set(int i)
{
smoothvol[i] = map(smoothvol[i], 0, 255, 0, 255); // map de 0 à 255
smoothvol[i] = constrain(smoothvol[i], 0, 255); // map de 0 à 255
relais_vol_val[i] = smoothvol[i]; // valeur du relais = valeur du volume
#ifdef DEBUG_RELAIS
Log.notice(F(CR "int smoothvolume_set()" CR));
Log.notice(F("i = %d" CR), i);
Log.notice(F("relais_vol_val = %d" CR), relais_vol_val[i]);
Log.notice(F("smoothvol = %d" CR), smoothvol[i]);
#endif
if (i == 0)
{
relais_set(1); // mise à jour des relais
}
if (i == 1)
{
relais_set(3); // mise à jour des relais
}
}
+130
View File
@@ -0,0 +1,130 @@
// *******************************************************************************************************
// ****************************************** PIN MAPPING ************************************************
// *******************************************************************************************************
// définition LED
#define const_out_L_led 5 // Digital OUT led const_out_L
#define const_out_R_led 6 // Digital OUT led const_out_R
#define stereo_link_led 7 // Digital OUT led stereo_link
// définition switch
#define const_out_sw_L 2 // Digital IN switch const_out_L
#define const_out_sw_R 3 // Digital IN switch const_out_R
#define stereo_link_sw 4 // Digital IN switch stereo_link
// définition PIN curseur potentiomètre
#define gain_0_pot A1 // entrée pot gain gauche
#define vol_0_pot A0 // entrée pot volume gauche
#define gain_1_pot A2 // entrée pot gain droite
#define vol_1_pot A3 // entrée pot volume droite
// *******************************************************************************************************
// ****************************************** potentiomètre **********************************************
// *******************************************************************************************************
// adresse moteur
#define gain_0_motor 0xC8 // A0 = open, A1 = 1
#define vol_0_motor 0xCE // A0 = open, A1 = open
#define gain_1_motor 0xD0 // A0 = 1, A1 = open
#define vol_1_motor 0xCA // A0 = 1, A1 = 1
// variables potentiomètre
int consigne[4] = {0, 0, 0, 0}; // tableau de consigne des potentiomètre
int position_lue[4] = {0, 0, 0, 0}; // tableau de valeur lus sur les potentiomètre
int position_set[4] = {0, 0, 0, 0}; // tableau de consigne de position des potentiomètre
int position_save[4] = {0, 0, 0, 0}; // tableau de sauvegarde de valeurs des potentiomètre
bool position_change[4] = {false, false, false, false}; // tableau de flag de positionnement des potentiomètre
bool motor_change[4] = {false, false, false, false}; // tableau de flag de changement de positionnement des potentiomètre
byte analog_pot[4] = {gain_0_pot, vol_0_pot, gain_1_pot, vol_1_pot}; // tableau de PIN des potentiomètre
unsigned long last_change_time = millis(); // remise à zéro du compteur de temps
#define bounce_time_pot 300 // interval de temps entre 2 lecture de l'état du potentiomètre
// *******************************************************************************************************
// ****************************************** relais *****************************************************
// *******************************************************************************************************
// adresse 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 0x00
#define vol_1_relais 0x00
// variables relais
byte relais_vol_val[2] = {0, 0}; // tableau de valeur des relais volumes
byte relais_gain_val[2] = {0, 0}; // tableau de valeur des relais gain
byte relais_old[4] = {0, 0, 0, 0}; // tableau de comparaison de valeur des relais
byte relais_map[4] = {0, 0, 0, 0}; // tableau de mappage des valeur des relais
// *******************************************************************************************************
// ****************************************** boutton *****************************************************
// *******************************************************************************************************
bool const_out_L_state_old = false; // variable de comparaison d'état du bouton const_out_L
bool const_out_R_state_old = false; // variable de comparaison d'état du bouton const_out_R
bool stereo_link_state_old = false; // variable de comparaison d'état du bouton stereo_link
bool const_out_L_state = false; // variable d'état du bouton const_out_L
bool const_out_R_state = false; // variable d'état du bouton const_out_R
bool stereo_link_state = false; // variable d'état du bouton stereo_link
#define interval_button 10 // interval de temps entre 2 lecture de l'état du bouton
// *******************************************************************************************************
// ****************************************** variable diverse *******************************************
// *******************************************************************************************************
bool state_pot_change[4] = {false, false, false, false}; // variable de changement d'état
bool state_button_change = true; // variable de changement d'état
int diff_gain; // variable de différence de valeur entre les 2 potentiomètre de gain
int diff_vol; // variable de différence de valeur entre les 2 potentiomètre de volume
int diff_const_out_L; // variable de différence de valeur du canal gauche
int diff_const_out_R; // variable de différence de valeur du canal droite
int smoothgain[2] = {0, 0}; // tableau de valeur de lissage du gain
int smoothvol[2] = {0, 0}; // tableau de valeur de lissage du volume
// ******************************************************************************************************
#ifdef DEBUG // si DEBUG activé
unsigned long last_time; // variable de comparaison de temps
#define interval_loop 1000 // variable de comparaison de temps
unsigned int debug_count = 1; // variable de comptage de boucle
void debug()
{
#ifdef DEBUG_LOOP_HARD // si DEBUG activé
Log.verbose(F("--------------------------------------------------" CR));
Log.verbose(F("----------------- DEBUG ------------------------" CR));
Log.verbose(F("--------------------------------------------------" CR));
Log.verbose(F("millis() = %d" CR), millis());
Log.verbose(F("last_time = %d" CR), last_time);
Log.verbose(F("interval_loop = %d" CR), interval_loop);
Log.verbose(F("state_pot_change = %d" CR), state_pot_change);
Log.verbose(F("state_button_change = %d" CR), state_button_change);
Log.verbose(F("stereo_link_state = %d" CR), stereo_link_state);
Log.verbose(F("const_out_L_state = %d" CR), const_out_L_state);
Log.verbose(F("const_out_R_state = %d" CR), const_out_R_state);
Log.verbose(F("stereo_link_state_old = %d" CR), stereo_link_state_old);
Log.verbose(F("const_out_L_state_old = %d" CR), const_out_L_state_old);
Log.verbose(F("const_out_R_state_old = %d" CR CR), const_out_R_state_old);
#ifdef DEBUG_LEFT
Log.verbose(F("diff_const_out_L = %d" CR), diff_const_out_L);
for (int i = 0; i <= 1; i++)
{
Log.verbose(F("--------< %d >--------" CR), i);
Log.verbose(F("position_save[%d] = %d" CR), i, position_save[i]);
Log.verbose(F("position_lue[%d] = %d" CR), i, position_lue[i]);
Log.verbose(F("position_set[%d] = %d" CR), i, position_set[i]);
Log.verbose(F("relais_old[%d] = %d" CR), i, relais_old[i]);
Log.verbose(F("relais_map[%d] = %d" CR), i, relais_map[i]);
}
#ifdef DEBUG_RIGHT
Log.verbose(F("diff_const_out_R = %d" CR CR), diff_const_out_R);
for (int i = 2; i <= 3; i++)
{
Log.verbose(F("--------< %d >--------" CR), i);
Log.verbose(F("position_save[%d] = %d" CR), i, position_save[i]);
Log.verbose(F("position_lue[%d] = %d" CR), i, position_lue[i]);
Log.verbose(F("position_set[%d] = %d" CR), i, position_set[i]);
Log.verbose(F("relais_old[%d] = %d" CR), i, relais_old[i]);
Log.verbose(F("relais_map[%d] = %d" CR), i, relais_map[i]);
}
#endif
last_time = millis(); // remise à zéro du compteur de temps
Log.verbose(F("--------------------------------------------------" CR));
Log.verbose(F("---------------- END DEBUG ---------------------" CR));
Log.verbose(F("--------------------------------------------------" CR));
#endif
#endif
}
#endif