/* prog rms to dc-V10
* Programme by ARGO
* LCD RS pin to digital pin 42
* LCD R/W pin to digital pin 43
* LCD Enable pin to digital pin 44
* LCD D4 pin to digital pin 46
* LCD D5 pin to digital pin 47
* LCD D6 pin to digital pin 48
* LCD D7 pin to digital pin 49
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(42, 44, 46, 47, 48, 49);
const int slaveSelectPin = 53;
const int BUTTON_ON_OFF = 33; //assignation pin bouton ON/OFF
const int relai = 10; //assignation pin commande relais ON/OFF (M/A)
const int RLED = 19; //assignation pin commande LED (red)
const int BLED = 18; //assignation pin commande LED (blue)
const int SOFT_START = 11; //assignation pin commande relais soft start
const int ENVdig = 12; // assignation pin commande enable reg 12V digital préamp
const int BUTTON_Vup = 37; //assignation pin bouton incrementation volume
const int BUTTON_Vdown = 36; //assignation pin bouton decrementation volume
const int BUTTON_INup = 35; //assignation pin bouton 1 RCA
const int BUTTON_INdown = 34; //assignation pin bouton 2 RCA
const int INPUT1 = 6; // assignation pin commande RELAIS IN1 RCA
const int INPUT2 = 16; // assignation pin commande RELAIS IN2 RCA
const int INPUT3 = 17; // assignation pin commande RELAIS IN3 RCA
const int INPUT4 = 7; // assignation pin commande RELAIS IN BLUETOOTH
const int INPUT5 = 9; // assignation pin commande RELAIS IN XLR
const int INPUT6 = 8; // assignation pin commande RELAIS IN PHONO
bool IN1 = HIGH; //sauve état RELAIS IN 1 RCA (1 par défaut)
bool IN2 = LOW; //sauve état RELAIS IN 2 RCA
bool IN3 = LOW; //sauve état RELAIS IN 3 RCA
bool IN4 = LOW; //sauve état RELAIS IN BLUETOOTH
bool IN5 = LOW; //sauve état RELAIS IN XLR
bool IN6 = LOW; //sauve état RELAIS IN PHONO
const int BUTTON_AFF = 25; //assignation pin bouton AFFICHAGE
const int cont_offset_L = 21; //assignation pin CONTROLE OFFSET L
const int cont_offset_R = A3; //assignation pin CONTROLE OFFSET R
const int com_relais_L = 38; //assignation pin commande RELAIS AMPLI L
const int com_relais_R = A4; //assignation pin commande RELAIS AMPLI R
bool offsetR = 0;
bool offsetL = 0;
bool offsetRdetected = 0; // variable de stockage de la detection d'une erreur d'offset.
bool offsetLdetected = 0;
bool val_ON_OFF = 0; // sauve etat bouton on/off
bool old_val_ON_OFF = 0;
bool val_Vup = 0; // sauve etat bouton incrementation
bool val_Vdown = 0; // sauve etat bouton decrementation
bool old_val_Vup = 0; // sauve etat precedent bouton incrementation volume
bool old_val_Vdown = 0; // sauve etat precedent bouton decrementation volume
bool val_BUTTON_INup = 0; //sauve état bouton select IN+
bool old_val_BUTTON_INup = 0;
bool val_BUTTON_INdown = 0; //sauve état bouton select IN-
bool old_val_BUTTON_INdown = 0;
bool val_BUTTON_AFF = 0; //sauve état bouton AFFICHAGE
bool old_val_BUTTON_AFF = 0;
unsigned long startTime_BU = 0; //depart chronometre bouton incrementation
unsigned long startTime_BD = 0; //depart chronometre bouton decrementation
int C = 1; //variable de stockage N° input
int AFF = 0; // Var de stockage fct AFFichage: 0 = normal;1=MUTE;2=temp;3=offset;4=RMS TO DC
int npot = 0; //variable de stockage valeur npot
float gainfloat = 0; // stocke valeur gain float (avec décimale)
int gain = 0; // stocke valeur gain (sans décimale)
int gaindec = 0;
const int VTR = A10; //assignation pin mesure temp rad droit
const int VTL = A0; //assignation pin mesure temp rad gauche A0 NORMALEMENT
int tempL = 0; // variable de stockage valeur température left
int tempR = 0;
const int Nval = 20; // nombre échantillon pour lissage mesure temp
unsigned long valVTR[Nval]; // variable de stockage de VTR mesuré indexé
unsigned long valVTL[Nval]; // variable de stockage de VTL mesuré indexé
int vali = 0; // Index de la lecture en cours temp
int valj = 0; // Index de la lecture en cours temp
float totalVTR = 0; // Total des mesures
float moyVTR = 0; // Moyenne des mesures
float totalVTL = 0; // Total des mesures
float moyVTL = 0; // Moyenne des mesures
bool errortemp = 0;
const int DC_L = A15; //assignation pin mesure RMS to DC left
const int DC_R = A14; //assignation pin mesure RMS to DC right
const int NmesuresV = 10; // nbre valeurs de mesures moyenne Vout
int DCR[NmesuresV]; // stockage valeur DC Right mesurée dans le tableau
int DCL[NmesuresV];
int VLoutrms=0;
int VRoutrms=0;
int valk = 0; // Index de la lecture en cours DCL
int valr = 0; // Index de la lecture en cours DCV
unsigned long totalDCR = 0; // Total des NmesuresV contenues dans le tableau
unsigned long totalDCL = 0; // Total des NmesuresV contenues dans le tableau
float moyDCL=0;
float moyDCR=0;
float VLout = 0; // stockage valeur V left moyen calculée
float VRout = 0; // stockage valeur V right moyen calculée
int PLout = 0; // stockage valeur P left calculée
int PRout = 0; // stockage valeur P left calculée
enum : byte { ampli_OFF,
ampli_ON } etat_ampli; //tableau état ampli (ON/OFF)
byte zero[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte one[] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000
};
byte two[] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000
};
byte three[] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100
};
byte four[] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110
};
byte five[] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
void setup() {
lcd.begin(20, 4);
pinMode(relai, OUTPUT);
pinMode(SOFT_START, OUTPUT);
pinMode(ENVdig, OUTPUT);
pinMode(BLED, OUTPUT);
pinMode(RLED, OUTPUT);
pinMode(BUTTON_ON_OFF, INPUT); //fixe pin bouton ON/OFF en entrée
pinMode(BUTTON_Vup, INPUT); //fixe pin bouton incrementation en entrée
pinMode(BUTTON_Vdown, INPUT); //fixe pin bouton decrementation en entrée
pinMode(BUTTON_INup, INPUT); //fixe pin bouton select INup en entrée
pinMode(BUTTON_INdown, INPUT); //fixe pin bouton select INdown en entrée
pinMode(BUTTON_AFF, INPUT); //fixe pin bouton select IN3 en entrée
pinMode(INPUT1, OUTPUT); //fixe pin IN1 en sortie
pinMode(INPUT2, OUTPUT); //fixe pin IN2 en sortie
pinMode(INPUT3, OUTPUT); //fixe pin IN3 en sortie
pinMode(INPUT4, OUTPUT); //fixe pin IN4 en sortie
pinMode(INPUT5, OUTPUT); //fixe pin IN5 en sortie
pinMode(INPUT6, OUTPUT); //fixe pin IN6 en sortie
pinMode(cont_offset_L, INPUT); //fixe pin offset L en entrée
pinMode(cont_offset_R, INPUT); //fixe pin offset R en entrée
pinMode(com_relais_L, OUTPUT); //fixe pin commande relais offset L en sortie
pinMode(com_relais_R, OUTPUT); //fixe pin commande relais offset R en sortie
for (int i = 0; i < Nval; i++) {
valVTR[i] = 0;
}
for (int j = 0; j < Nval; j++) {
valVTL[j] = 0;
}
for (int k = 0; k < NmesuresV; k++) {
DCL[k] = 0;
}
for (int r = 0; r < NmesuresV; r++) {
DCR[r] = 0;
}
lcd.createChar(6, zero);
lcd.createChar(1, one);
lcd.createChar(2, two);
lcd.createChar(3, three);
lcd.createChar(4, four);
lcd.createChar(5, five);
etat_ampli = ampli_OFF;
//AFF = 0;
//C = 1;
}
void loop() {
float gainfloat = (31.5 - (0.5 * (255 - npot))); // stocke valeur gain float (avec décimale)
int gain = (31.5 - (0.5 * (255 - npot))); // stocke valeur gain (sans décimale)
int gaindec = abs(10 * (gain - gainfloat));
// gestion contrôle température
totalVTR = totalVTR - valVTR[vali]; // retranche la dernière lecture VTR
totalVTL = totalVTL - valVTL[valj]; // retranche la dernière lecture VTL
analogRead(VTR);
valVTR[vali] = analogRead(VTR); // lecture capteur R
analogRead(VTL);
valVTL[valj] = analogRead(VTL); // lecture capteur G
totalVTR = totalVTR + valVTR[vali]; // Ajoute lecture au total
totalVTL = totalVTL + valVTL[valj]; // Ajoute lecture au total
vali = vali + 1; // incrémentation index
valj = valj + 1; // incrémentation index
if (vali >= Nval) { vali = 0; } // remise à 0 de la boucle
if (valj >= Nval) { valj = 0; } // remise à 0 de la boucle
moyVTR = totalVTR / Nval; // calcule la moyenne R
moyVTL = totalVTL / Nval; // calcule la moyenne L
tempR = (moyVTR * 4.89 / 10) - 273; // transpose lecture VTR en °C Retrancher 273 si LM235
tempL = (moyVTL * 4.89 / 10) - 273; // transpose lecture VTL en °C Retrancher 273 si LM235
if (tempR > 90 || tempL > 90) {
do {
digitalWrite(BLED, LOW);
digitalWrite(relai, LOW);
digitalWrite(com_relais_L, LOW);
digitalWrite(com_relais_R, LOW);
digitalWrite(SOFT_START, LOW);
//analogWrite(ventL, 255);
//analogWrite(ventR, 255);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" ERREUR TEMPERATURE ");
lcd.setCursor(0, 1);
lcd.print(" MESURE TEMP > 90 C ");
lcd.setCursor(0, 2);
lcd.print(" REPORTEZ VOUS AU ");
lcd.setCursor(0, 3);
lcd.print("MANUEL D'UTILISATION");
digitalWrite(RLED, HIGH);
delay(500);
digitalWrite(RLED, LOW);
delay(500);
errortemp=1;
} while ((analogRead(VTR) > 722 && analogRead(VTL) > 722));
} // arrêt de l'ampli si T > 90°, avec impossibilite de l'allumer tant que T>80°C; VTR>722 si LM235 ou ? si LM35
// mesures et calculs moyennes glissantes V et P out
totalDCR = (totalDCR - DCR[valr]); // retranche la dernière lecture VTR
DCR[valr] = analogRead(DC_R); // lecture capteur R
totalDCR = (totalDCR + DCR[valr]); // retranche la dernière lecture VTR
valr = (valr + 1); // incrémentation index
if (valr >= NmesuresV) { valr = 0; } // remise à 0 de la boucle
moyDCR= (totalDCR/NmesuresV);
VRout = (moyDCR*0.00489); // stockage valeur V left moyen calculée
VRoutrms=(10*VRout);
PRout=(sq(VRoutrms)/8); // stockage valeur P left calculée
totalDCL = (totalDCL - DCL[valk]); // retranche la dernière lecture VTR
DCL[valk] = analogRead(DC_L); // lecture capteur R
totalDCL = (totalDCL + DCL[valk]); // retranche la dernière lecture VTR
valk = (valk + 1); // incrémentation index
if (valk >= NmesuresV) {
valk = 0;
} // remise à 0 de la boucle
moyDCL= (totalDCL/NmesuresV);
VLout = (moyDCL*0.00489); // stockage valeur V left moyen calculée
VLoutrms=(10*VLout);
PLout=(sq(VLoutrms)/8); // stockage valeur P left calculée
val_ON_OFF = digitalRead(BUTTON_ON_OFF);
if ((val_ON_OFF == HIGH) && (old_val_ON_OFF == LOW)) {
switch (etat_ampli) {
case ampli_OFF:
lcd.setCursor(0, 0);
lcd.print(" ARGO ON ");
lcd.setCursor(0, 1);
lcd.print(" WELCOME ");
lcd.setCursor(0, 2);
lcd.print("...initialisation...");
delay(100); //RAJOUTER UN 0 A CHAQUE DELAY
digitalWrite(relai, HIGH);
delay(50);
digitalWrite(SOFT_START, HIGH);
lcd.setCursor(0, 3);
lcd.print("controle de l'offset");
delay(200);
digitalWrite(RLED, LOW);
digitalWrite(BLED, HIGH);
etat_ampli = ampli_ON;
break;
case ampli_ON:
lcd.clear();
lcd.setCursor(0, 1);
lcd.print(" ARGO OFF ");
lcd.setCursor(0, 2);
lcd.print(" GOOD BYE ");
delay(500);
digitalWrite(com_relais_L,LOW);
digitalWrite(com_relais_R,LOW);
delay(1000);
digitalWrite(relai, LOW);
digitalWrite(SOFT_START, LOW);
digitalWrite(RLED, HIGH);
digitalWrite(BLED, LOW);
lcd.clear();
etat_ampli = ampli_OFF;
break;
}
//digitalPotWrite(npot);
}
old_val_ON_OFF = val_ON_OFF;
if (etat_ampli == ampli_ON) {
offsetL = digitalRead(cont_offset_L);
if (offsetL == HIGH) {
do {digitalWrite(com_relais_L, LOW);
lcd.setCursor(0,0);
lcd.print(" error offset Left ");
lcd.setCursor(0,1);
lcd.print("consultez le manuel ");
lcd.setCursor(0,2);
lcd.print(" d'utilisation ");
}
while (digitalRead(cont_offset_L)==HIGH);
}
offsetR = digitalRead(cont_offset_R);
if (offsetR == HIGH) {
do {digitalWrite(com_relais_R, LOW);
lcd.setCursor(0,0);
lcd.print(" error offset Right ");
lcd.setCursor(0,1);
lcd.print("consultez le manuel ");
lcd.setCursor(0,2);
lcd.print(" d'utilisation ");
}
while (digitalRead(cont_offset_R)==HIGH);
}
if ((tempR<=80) && (tempL<=80) && (errortemp==1)) {
digitalWrite(relai, HIGH);
delay(500);
digitalWrite(SOFT_START, HIGH);
errortemp=0;
}
if (errortemp==0){
digitalWrite(com_relais_L, HIGH);
digitalWrite(com_relais_R, HIGH);
digitalWrite(ENVdig, HIGH);
if (C == 1) {
IN1 = HIGH;
IN2 = LOW;
IN3 = LOW;
IN4 = LOW;
IN5 = LOW;
IN6 = LOW;
}
if (C == 2) {
IN1 = LOW;
IN2 = HIGH;
IN3 = LOW;
IN4 = LOW;
IN5 = LOW;
IN6 = LOW;
}
if (C == 3) {
IN1 = LOW;
IN2 = LOW;
IN3 = HIGH;
IN4 = LOW;
IN5 = LOW;
IN6 = LOW;
}
if (C == 4) {
IN1 = LOW;
IN2 = LOW;
IN3 = LOW;
IN4 = HIGH;
IN5 = LOW;
IN6 = LOW;
}
if (C == 5) {
IN1 = LOW;
IN2 = LOW;
IN3 = LOW;
IN4 = LOW;
IN5 = HIGH;
IN6 = LOW;
}
if (C == 6) {
IN1 = LOW;
IN2 = LOW;
IN3 = LOW;
IN4 = LOW;
IN5 = LOW;
IN6 = HIGH;
}
digitalWrite(INPUT1, IN1);
digitalWrite(INPUT2, IN2);
digitalWrite(INPUT3, IN3);
digitalWrite(INPUT4, IN4);
digitalWrite(INPUT5, IN5);
digitalWrite(INPUT6, IN6);
if (VLoutrms >= 28.3 || VRoutrms >= 28.3) {
do {
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" OVERLOAD ");
lcd.setCursor(0, 2);
lcd.print(" OVERLOAD ");
delay(500);
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
delay(200);
}
while ((analogRead(DC_L) > 578) || (analogRead(DC_R) > 578));
} // clignote si P > 100W
if(AFF==0){
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
if (C == 1) {
lcd.setCursor(0, 1);
lcd.print(" Input RCA 1 ");
}
if (C == 2) {
lcd.setCursor(0, 1);
lcd.print(" Input RCA 2 ");
}
if (C == 3) {
lcd.setCursor(0, 1);
lcd.print(" Input RCA 3 ");
}
if (C == 4) {
lcd.setCursor(0, 1);
lcd.print(" Input BLUETOOTH ");
}
if (C == 5) {
lcd.setCursor(0, 1);
lcd.print(" Input XLR ");
}
if (C == 6) {
lcd.setCursor(0, 1);
lcd.print(" Input PHONO ");
}
char tamponA[20] = "";
lcd.setCursor(0, 2);
sprintf(tamponA, " gain =%3d.%1d dB ", gain, gaindec);
lcd.print(tamponA);
lcd.setCursor(0, 3);
lcd.print(" ");
}
if(AFF==1){
char tamponB[20] = "";
lcd.setCursor(0, 0);
sprintf(tamponB, " Temp Left=%2d%cC ",tempL, 0xDF); // "T L=50°C T R=51°C"
lcd.print(tamponB);
lcd.setCursor(0, 1);
lcd.print(" ");
char tamponC[20] = "";
lcd.setCursor(0, 2);
sprintf(tamponC, " Temp right=%2d%cC ",tempR, 0xDF);
lcd.print(tamponC);
lcd.setCursor(0, 3);
lcd.print(" ");
}
if(AFF==2){
char tamponD[20] = "";
lcd.setCursor(0, 0);
sprintf(tamponD, " V L=%2d V P L=%3d W",VLoutrms,PLout);
lcd.print(tamponD);
lcd.setCursor(0, 3);
char tamponE[20] = "";
sprintf(tamponE, " V R=%2d V P R=%3d W",VRoutrms,PRout);
lcd.print(tamponE);
//lcd.print(" ");
//lcd.print(" ");
//lcd.setCursor(0, 1);
//lcd.print(" ");
//lcd.setCursor(0, 2);
//lcd.print(" ");
updateProgressBar(moyDCL, 600);
updateProgressBar2(moyDCR, 600);
/*
DCLbin=analogRead(DC_L);
lcd.setCursor(0,0);
lcd.print(DCLbin);
VLout=DCLbin*0.00488;
lcd.setCursor(0,1);
lcd.print(VLout);
VLoutrms=(10*VLout/sqrt(2));
PLout=(sq(VLoutrms)/8);
lcd.setCursor(0,2);
lcd.print(PLout);
*/
//updateProgressBar(VRout, 1023);
}
val_Vup = digitalRead(BUTTON_Vup);
if ((val_Vup == HIGH) && (old_val_Vup == LOW)) {
npot++;
if (npot > 256) { npot = 256; }
//digitalPotWrite(npot);
startTime_BU = millis();
}
if ((val_Vup == HIGH) && (old_val_Vup == HIGH)) { //teste si bouton resté enfoncé
if ((millis() - startTime_BU) > 1000) //teste durée d'appui
{
npot++; // si vrai alors incrementation du niveau de 1
delay(50); //delai d'incrementation auto si bouton reste enfoncé
if (npot > 255) {
npot = 255; // atteinte niveau max
}
//digitalPotWrite(npot);
}
}
old_val_Vup = val_Vup;
val_Vdown = digitalRead(BUTTON_Vdown);
if ((val_Vdown == HIGH) && (old_val_Vdown == LOW)) {
npot--;
if (npot < 0) { npot = 0; }
//digitalPotWrite(npot);
startTime_BU = millis();
}
if ((val_Vdown == HIGH) && (old_val_Vdown == HIGH)) { //teste si bouton resté enfoncé
if ((millis() - startTime_BU) > 1000) //teste durée d'appui
{
npot--; // si vrai alors incrementation du niveau de 1
delay(50); //delai d'incrementation auto si bouton reste enfoncé
if (npot < 0) {
npot = 0; // atteinte niveau max
}
//digitalPotWrite(npot);
}
}
old_val_Vdown = val_Vdown;
val_BUTTON_INup = digitalRead(BUTTON_INup);
if ((val_BUTTON_INup == HIGH) && (old_val_BUTTON_INup == LOW)) {
C = C + 1;
if (C == 7) { C = 1; }
delay(20);
}
old_val_BUTTON_INup = val_BUTTON_INup;
val_BUTTON_INdown = digitalRead(BUTTON_INdown);
if ((val_BUTTON_INdown == HIGH) && (old_val_BUTTON_INdown == LOW)) {
C = C - 1;
if (C == 0) { C = 6; }
delay(20);
}
old_val_BUTTON_INdown = val_BUTTON_INdown;
val_BUTTON_AFF = digitalRead(BUTTON_AFF);
if ((val_BUTTON_AFF == HIGH) && (old_val_BUTTON_AFF == LOW)) {
AFF = AFF + 1;
if (AFF == 3) { AFF = 0; }
delay(20);
}
old_val_BUTTON_AFF = val_BUTTON_AFF;
}
}
if (etat_ampli == ampli_OFF){
digitalWrite(ENVdig, LOW);
lcd.clear();
digitalWrite(INPUT1, LOW);
digitalWrite(INPUT2, LOW);
digitalWrite(INPUT3, LOW);
digitalWrite(INPUT4, LOW);
digitalWrite(INPUT5, LOW);
digitalWrite(INPUT6, LOW);
}
}
void updateProgressBar(unsigned long count, unsigned long totalCount) {
double factor = (totalCount / 100.0); //See note above!
int percent = ((count + 1) / factor);
int number = (percent / 5);
int remainder = (percent % 5);
if (number > 0) {
for (int s = 0; s < number; s++) {
lcd.setCursor(s, 1);
lcd.write(5);
}
}
lcd.setCursor(number, 1);
lcd.write(remainder);
if (number < 20) {
for (int s = number + 1; s <= 20; s++) {
lcd.setCursor(s, 1);
lcd.write(6);
}
}
}
void updateProgressBar2(unsigned long count, unsigned long totalCount) {
double factor = totalCount / 100.0; //See note above!
int percent = (count + 1) / factor;
int number = percent / 5;
int remainder = percent % 5;
if (number > 0) {
for (int l = 0; l < number; l++) {
lcd.setCursor(l, 2);
lcd.write(5);
}
}
lcd.setCursor(number, 2);
lcd.write(remainder);
if (number < 20) {
for (int l = number + 1; l <= 20; l++) {
lcd.setCursor(l, 2);
lcd.write(6);
}
}
}
(click to edit)
TEMPERATURE
OFFSET
DIG
mesures V out