Arduino Millis on the LCD
<p>I want to display the millis on the LCD 16x2, but the problem is that counter does not start from zero after I have added MySQL insert code. Actually, sometimes the connection to the server starts after 4 sec, 40 sec, and sometimes 79 sec.</p>

<p>The type of Arduino I am using is: "Arduino Uno",
and Arduino IDE Version is 1.6.7.</p>

<p>Could anyone help me to fix this problem, and here is the code:</p>

<pre><code>#include &lt;Ethernet.h&gt;
#include &lt;LiquidCrystal.h&gt;
#include &lt;MySQL_Connection.h&gt;
#include &lt;MySQL_Cursor.h&gt;

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr();  // IP of the MySQL *server* here

char user[] = "";              // MySQL user login username
char password[] = "";        // MySQL user login password


EthernetClient client;
MySQL_Connection conn((Client *)&amp;client);

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() {

 // set up the LCD's number of columns and rows:
lcd.begin(16, 2);

// Print a message to the LCD.
lcd.print("Millis");

Serial.begin(115200);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr);
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}

else
Serial.println("Connection failed.");  
}


void loop() {

unsigned long var =(millis()/1000);

if(var%40 == 0)
{

char INSERT_SQL[] = "UPDATE Information.total SET reading=(%d) WHERE 
Name='Sam';";
char query[255];
sprintf(query, INSERT_SQL, var);
MySQL_Cursor *cur_mem = new MySQL_Cursor(&amp;conn);
cur_mem-&gt;execute(query);

delete cur_mem;

}  

lcd.setCursor(0, 1);
lcd.print(var);

}
</code></pre>

<p>ِAnd, here is the other code in which the millis start from Zero (Before inserting MySQL insert code):</p>

<pre><code> #include &lt;LiquidCrystal.h&gt;

 LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

 void setup() {
 lcd.begin(16, 2);
 Serial.begin(9600);
 lcd.print("Millis");

 }

 void loop() {
 unsigned long var =(millis()/1000);
 var = (var==0)?1:var;
 if(var%40 == 0)
 {
 Serial.println("Millis: ");
 Serial.println(var);
  }  
 lcd.setCursor(0, 1);
 lcd.print(millis()/1000);
 delay(1000);
 }
</code></pre>

<p>All answers are appreciated…</p>