Expected initializer before "+=" token [FR]

Bonjour, cous l’avez vue dans le titre j’ai un problème, quand je vérifie mon code ca me dit “expected initializer before ‘+=’ token”
Cependant je ne comprend pas pourquoi car je l’ai déja déclarer dans mon programme…
L’erreur se trouve ligne 68, voici mon code:

// C++ code
//
#include "EmonLib.h"
#include "LiquidCrystal.h"

EnergyMonitor emon1;
LiquidCrystal lcd(11,10,5,4,3,2);

int capteur_temp=1;
int capteur_courant=0;
int tension= 230;
int relai=13;
int start=1;
int afficheconso=12;
int sortie=0;
int total_time = 0;

void setup()
{
  emon1.current(capteur_courant, 12.5); // calibration = Ratio/res.burden = 2000/160 = 12.5
  pinMode(relai, OUTPUT);
  pinMode(start, INPUT);
  pinMode(afficheconso, INPUT);
  pinMode(sortie, OUTPUT);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.clear();
}

void loop()
{
  int pTotal=0;
  int rep=0;
  int prev= millis();
  int Total_time = 0;
  while (start == 1)
  {
    digitalWrite(sortie, 1);
    float temp=analogRead(capteur_temp)*(5.0/1023.0*100.0);
    if (temp>70)
    {
      digitalWrite(relai, 0);
      while (temp>30)
      {
        float temp=analogRead(capteur_temp)*(5.0/1023.0*100.0);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Surchauffe");
        lcd.setCursor(0,1);
        lcd.print("temp:");
        lcd.print(temp);
        delay(500);
      }
      
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("REDEMARAGE");
      delay(5000);
      break;
    }

    double Irms = emon1.calcIrms(1480);
    int puissance = Irms*tension;
    int pTotal += puissance;
    int rep += 1;
    int looptime = millis()- prev;
    int prev = millis();
    int Total_time += looptime;
    lcd.clear();
    lcd.setCursor(0,0);
    if (afficheconso == 1)
    {
      int conso = (pTotal*total_time)/3600000
      lcd.print("Conso:");
      lcd.print(conso);
      lcd.print("Wh");
    }
    
    else
    {
      lcd.print("P:");
      lcd.print(puissance);
      lcd.print("W");
    }
    
    lcd.setCursor(0,1);
    lcd.print("temp:");
    lcd.print(temp);
    delay(500);
    
  }
  
  digitalWrite(sortie=0);
  while (start == 0)
  {
    delay(1);
  }
        
}

Merci d’avance pour votre aide :slight_smile:

Greetings,
I think I solved your problem.

// C++ code
//
#include "EmonLib.h"
#include "LiquidCrystal.h"

EnergyMonitor emon1;
LiquidCrystal lcd(11,10,5,4,3,2);

int capteur_temp=1;
int capteur_courant=0;
int tension= 230;
int relai=13;
int start=1;
int afficheconso=12;
int sortie=0;
int total_time = 0;

void setup()
{
  emon1.current(capteur_courant, 12.5); // calibration = Ratio/res.burden = 2000/160 = 12.5
  pinMode(relai, OUTPUT);
  pinMode(start, INPUT);
  pinMode(afficheconso, INPUT);
  pinMode(sortie, OUTPUT);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.clear();
}

void loop()
{
  int pTotal=0;
  int rep=0;
  int prev= millis();
  int Total_time = 0;
  while (start == 1)
  {
    digitalWrite(sortie, 1);
    float temp=analogRead(capteur_temp)*(5.0/1023.0*100.0);
    if (temp>70)
    {
      digitalWrite(relai, 0);
      while (temp>30)
      {
        float temp=analogRead(capteur_temp)*(5.0/1023.0*100.0);
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Surchauffe");
        lcd.setCursor(0,1);
        lcd.print("temp:");
        lcd.print(temp);
        delay(500);
      }
      
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("REDEMARAGE");
      delay(5000);
      break;
    }

    double Irms = emon1.calcIrms(1480);
    int puissance = Irms*tension;
    int pTotal;
    pTotal += puissance;
    int rep;
    rep += 1;
    int looptime = millis()- prev;
    int prev = millis();
    int Total_time;
    Total_time += looptime;
    lcd.clear();
    lcd.setCursor(0,0);
    if (afficheconso == 1)
    {
      int conso = (pTotal*total_time)/3600000
      lcd.print("Conso:");
      lcd.print(conso);
      lcd.print("Wh");
    }
    
    else
    {
      lcd.print("P:");
      lcd.print(puissance);
      lcd.print("W");
    }
    
    lcd.setCursor(0,1);
    lcd.print("temp:");
    lcd.print(temp);
    delay(500);
    
  }
  
  digitalWrite(sortie=0);
  while (start == 0)
  {
    delay(1);
  }
        
}

Try this.

yep it work, but why? I don’t understand what was my mistake :confused:

Greetings,
I don’t know why. I think you should create the variable before you change it.

hmmm Ok thanks anyway you help me well :slight_smile:

L’opérateur += implique que la variable utilisée contiennent déjà une valeur avant de l’utiliser.

total_time += looptime;

int conso = (pTotal*total_time)/3600000ul ;

digitalWrite(sortie, 0);