thermal printing routine programming problem

My program checks on a button status, when press will set the variable printStatus =1
In my loop program, printStatus is checked and if is true, will invoke the printing routine.
After printing, the next statement printStatus =0 will set the variable back to 0 so no further printing until the button is press again.

When ever it prints, it always print twice (i.e. the printing is repeated two time)
Where ever I place the printStatus = 0 , it always prints twice
Not sure what have I missed out :frowning:
Its running on the DUE

The printing routine here:-

//Printing the logTime of the Dayrun
void printLogStatus()
{ 
  
  printer.print("Day Job Started on"); 
  printer.write(10);
  printer.print("Date: ");
  printer.print(logdayOfMonth, DEC);
  printer.print("-");
  printer.print(logmonth, DEC);
  printer.print("-20");
  printer.print(logyear, DEC);
  printer.print ("  Time = "); 
  printer.print(loghour, DEC);
  // convert the byte variable to a decimal number when displayed
  printer.print(":");
  if (logminute<10)
  {
    printer.print("0");
  }
  printer.print(logminute, DEC);
  printer.print(":");
  if (logsecond<10)
  {
    printer.print("0");
  }
  printer.print(logsecond, DEC);
  printer.print(" ");
  printer.write(10);
  printer.write(10);
  printer.write(10);
}

The loop routine here:

 void loop()
  {
 pulsecount();
 startprg();
 printingButton();
 if (printStatus == true){
  printLogStatus();
  printStatus=0;
  
  
  }
  }

OK ...The above prinLogStatus() routine may not be the problem.... I tried isolating and the printing routine is ok

  void loop()
  {
    
 pulsecount();
 startprg();
// printingButton();
// if (printStatus == true){
  printLogStatus(); // just do one time to check what was printed
  while(1>0);
//  printStatus=0;
  
  
  }
//  }

So could the problem be here ?

// ISR to check if the button was press...(without using delay) and turn output "on" for 5 secs
// also set the printStatus = 1
void orangButtonISR()
 { 
  unsigned long last = 0;
 
    if( (millis() - last ) > 20 ) //if at least 20 ms has passed since last press, this is not a dup
    {
        last = millis(); //note the time, for ignoring duplicate presses
        turnOff = true;
        offAt = millis() + 5000; //save a variable of now + 5 seconds
        digitalWrite(orangeLight, HIGH); //turn ON LED
        printStatus = 1;
    }
}


void printingButton()
{ 
  if(turnOff)
  {
   if(millis() >= offAt)
    { digitalWrite(orangeLight, LOW);} //turn off led
    
      }
    }

:slight_smile: :slight_smile: I solved my own problem....its in the void printingButton() routine and where to put the clear printStatus variable.

void printingButton()
{ 
  if(turnOff)
  {
   if(millis() >= offAt)
    { digitalWrite(orangeLight, LOW); //turn off led
       if (printStatus == true)
  printLogStatus();
    }
    }
}

Thks anyway :slight_smile: