Now I have another problem

here his the loop part:

void loop() {
int Exp6 = 0;      //temps exposition 650 nm
int Exp8 = 0;      //temps exposition 810 nm
bool Stop6 = 0;    //fin exposition 650 nm
bool Stop8 = 0;    //fin exposition 810 nm 
if (changeindex == 1)
  { 
  affiche_lcd(compteur);
  changeindex = 0;
  }
if (Expose == 1)
  {
  Expose = 0;
  Exp6 = exposition6[compteur];
  Exp8 = exposition8[compteur];
  Stop6 = 0;
  Stop8 = 0;
  Serial.print(F("Stop6 "));
  Serial.print(Stop6);
  Serial.print(F("  Stop8 "));
  Serial.print(Stop8);
  Serial.print(F("  Exp6 "));
  Serial.print(Exp6);
  Serial.print(F("   Exp8 "));
  Serial.println(Exp8);

  if(Stop6 > 0 && Stop8 > 0)
    {
    }
  else 
    {
    if (Exp6 > 0)
      {
      Allume650();
      Exp6 = Exp6 - 1;
      }  
    else
      {
      Eteint650();
      Stop6 = 1;
      }
    if (Exp8 > 0)
      {
      Allume810();
      Exp8 = Exp8 -1;
      }
    else
      {
      Eteint810();
      Stop8 = 1;
      }
    }
  }  
  delay(550);
  Serial.print(F("Stop6 "));
  Serial.print(Stop6);
  Serial.print(F("  Stop8 "));
  Serial.print(Stop8);
  Serial.print(F("  Exp6 "));
  Serial.print(Exp6);
  Serial.print(F("   Exp8 "));
  Serial.println(Exp8);

} 

And the monitor output:

Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Bouton SW relâché
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 104 Exp8 14
Stop6 0 Stop8 0 Exp6 103 Exp8 13
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0
Stop6 0 Stop8 0 Exp6 0 Exp8 0

I want to have Exp6 & Exp8 decrementing by one until they both reach 0

Thanks for your help

Sorry, that makes no sense at all, since they both begin life at 0 at the top of loop().

2 Likes

Please post your full sketch. And don't refer us to your other topic; I'm tempted to merge your two topics but decided to leave it like this.

there are several problems

  • these variables need to be global in order to maintain their values between iterations of loop() otherwise they just get re-initialized to zero
  • your coding is awkward. Is there a need for Stop6 and Stop8. Shouldn't Exposebe reset once both Exp6 and Exp8 become zero?

Output

Allume650
Allume810
          Exp6 5, Exp8 7
Allume650
Allume810
          Exp6 4, Exp8 6
Allume650
Allume810
          Exp6 3, Exp8 5
Allume650
Allume810
          Exp6 2, Exp8 4
Allume650
Allume810
          Exp6 1, Exp8 3
Allume650
Allume810
          Exp6 0, Exp8 2
Eteint650
Allume810
          Exp6 0, Exp8 1
Eteint650
Allume810
          Exp6 0, Exp8 0
  done

int compteur     = 0;
int Expose;

int exposition6 [6] = { 6 };
int exposition8 [8] = { 8 };

void Allume650   ()      { Serial.println (__func__); }
void Allume810   ()      { Serial.println (__func__); }

void Eteint650   ()      { Serial.println (__func__); }
void Eteint810   ()      { Serial.println (__func__); }

int  Exp6  = 0;      //temps exposition 650 nm
int  Exp8  = 0;      //temps exposition 810 nm

char s [90];

// -----------------------------------------------------------------------------
void loop()
{
    if (Expose == 1) {
        if (Exp6 > 0) {
            Allume650();
            Exp6--;
        }
        else
            Eteint650();

        if (Exp8 > 0) {
            Allume810();
            Exp8--;
        }
        else
            Eteint810();

        sprintf (s, "          Exp6 %d, Exp8 %d", Exp6, Exp8);
        Serial.println (s);

        if (0 == Exp6 && 0 == Exp8)  {
            Expose = 0;
            Serial.println ("  done");
        }
    }

    // delay(550);
}

// -----------------------------------------------------------------------------
void setup ()
{
    Serial.begin (9600);
    Serial.println ();
    Exp6   = exposition6 [compteur];
    Exp8   = exposition8 [compteur];
    Expose = 1;
}

Or static in loop() :wink:

Thanks,
I made your suggestions and everything is OK

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.