Convert char (arrays of chars) to int

GolamMostafa:
You have received only 8-byte data (probably BCD format) consisting of:
Hrs: xxxxxxxxxxxx (12-digit) //6-byte
Min: xx (2-digit) //1-byte
Sec: xx (2-digit) //1-byte

Example code:

byte buf[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x45, 0x37};

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 for (int i = 0; i < 8; i++)
 {
   byte x = buf[i];
   if (x < 0x10)
   {
     Serial.print('0');     //print leading zero
   }
   Serial.print(x, HEX);
   if (i == 5)
   {
     Serial.print(':');// show : as separator between Hrs and Min
   }
   else
   {
     if (i == 6)
     {
       Serial.print(':'); //show : as separator between Min and Sec
     }
   }
 }
 Serial.println();
 delay(1000);
}



![smz.png|608x403](upload://8g4P0liRqVAsmA0Ex0u1AFTaQ14.png)

after modification Slave code is here:-

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

//#define VCCSTATE SH1106_SWITCHCAPVCC
#define WIDTH     128
#define HEIGHT     64
#define NUM_PAGE    8
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

const byte slaveAddress1 = 4;
byte buf[8] = {}; //;
//byte buf[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
bool flag = false; 

void setup()
{
  Serial.begin(9600);
  Wire.begin(slaveAddress1);        
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Wire.onReceive(receiveEvent);
}

void loop()
{
  if (flag == true)
  {
   
  
   display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);

  //display.print(x);
  display.display(); 
  delay(1000);
  
  }
  
flag == false;
}

void receiveEvent(int howMany)
{
  
  
    for (int i = 0; i < 8; i++)
    {

      buf[i] = Wire.read();   //"buf"need to convert an integar value
      byte x = buf[i];
    /*if (x < 0x10)
    {
      Serial.print('0');     //print leading zero
    }*/
    Serial.print(x, HEX);
    if (i == 5)
    {
      Serial.print(':');// show : as separator between Hrs and Min
    }
    else
    {
      if (i == 6)
      {
        Serial.print(':'); //show : as separator between Min and Sec
      }
     }
    
    }
   Serial.println();
  
   
flag = true;
  }

Serial Monitor shows:-

000009:26:22
000009:26:23
000009:26:24
000009:26:25
000009:26:26
000009:26:27
000009:26:28
000009:26:29
000009:26:2A
000009:26:2B
000009:26:2C
000009:26:2D
000009:26:2E
000009:26:2F
000009:26:30
000009:26:31
000009:26:32
000009:26:33
000009:26:34
000009:26:35
000009:26:36

Now hours and minutes seperated by ":", but last digit of second showing alphabets.Why this showing alphabets A-F than come to digits.

Because you’re printing in HEX

TheMemberFormerlyKnownAsAWOL:
Because you’re printing in HEX

thanks after removing “HEX” from the code.

 Serial.print(x);

Now serial monitor shows correct.

000010:7:16
000010:7:17
000010:7:18
000010:7:20
000010:7:21
000010:7:22
000010:7:23
000010:7:24
000010:7:25
000010:7:26

Slave code is here:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

//#define VCCSTATE SH1106_SWITCHCAPVCC
#define WIDTH     128
#define HEIGHT     64
#define NUM_PAGE    8
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

const byte slaveAddress1 = 4;
byte buf[9] = {}; //;
//byte buf[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
bool flag = false; 

void setup()
{
  Serial.begin(9600);
  Wire.begin(slaveAddress1);        
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Wire.onReceive(receiveEvent);
}

void loop()
{
  if (flag == true)
  {
   
  byte x = buf[8];
    display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);

  display.print(x);
  display.display(); 
  delay(1000);
    
  
  flag == false;
}
}
void receiveEvent(int howMany)
{
  
  for (int i = 0; i < 8; i++)
    {

      buf[i] = Wire.read();   //"buf"need to convert an integar value
      byte x = buf[i];
    /*if (x < 0x10)
    {
      Serial.print('0');     //print leading zero
    }*/
    Serial.print(x);
    if (i == 5)
    {
      Serial.print(':');// show : as separator between Hrs and Min
    }
    else
    {
      if (i == 6)
      {
        Serial.print(':'); //show : as separator between Min and Sec
      }
     }
   
  
    }
   Serial.println();
  flag = true;
   
    
  }

But oled display shows only “0”.Please help me to find out mistakes.

You’re only printing the last byte of buf

TheMemberFormerlyKnownAsAWOL:
You’re only printing the last byte of buf

Can i add this code in main loop is it correct?

for (int r=0;r<8;r++){
byte x=buf[r];

display . print (x);
}

What happened when you tried it?

TheMemberFormerlyKnownAsAWOL:
What happened when you tried it?

After adding " for{} " in main loop Oled showing only last two digits (seconds) .

Slave code is here:-

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

//#define VCCSTATE SH1106_SWITCHCAPVCC
#define WIDTH     128
#define HEIGHT     64
#define NUM_PAGE    8
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

const byte slaveAddress1 = 4;
byte buf[9] = {}; //;
//byte buf[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
bool flag = false; 

void setup()
{
  Serial.begin(9600);
  Wire.begin(slaveAddress1);        
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Wire.onReceive(receiveEvent);
}

void loop()
{
  if (flag == true)
  {
 for (int r=0; r<8;r++){  
  byte y = buf[r];
    display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);

  display.print(y);
   display.display();
   }
  
  delay(1000);
    
  
  flag == false;
}
}
void receiveEvent(int howMany)
{
  
  for (int i = 0; i < 8; i++)
    {

      buf[i] = Wire.read();   //"buf"need to convert an integar value
      byte x = buf[i];
    /*if (x < 0x10)
    {
      Serial.print('0');     //print leading zero
    }*/
    Serial.print(x);
    if (i == 5)
    {
      Serial.print(':');// show : as separator between Hrs and Min
    }
    else
    {
      if (i == 6)
      {
        Serial.print(':'); //show : as separator between Min and Sec
      }
     }
   
  
    }
   Serial.println();
  flag = true;
   
    
  }
  

OLED Showing only the last two digits (seconds).How can display  all the data on OLED,as it is serial monitor displaying?

Why are you re-positioning the cursor at the same place again and again?
Try these codes:

void loop()
{
  if (flag == true)
  {
     display.setCursor(0, 0);
     for (int r=0; r<8;r++)
    { 
       byte y = buf[r];
       display.clearDisplay();
       display.setTextSize(1);
       display.setTextColor(WHITE);
       // display.setCursor(0, 0);
       display.print(y);
       display.display();
    }
    delay(1000);
    flag == false;
  }
}

GolamMostafa:
Why are you re-positioning the cursor at the same place again and again?
Try these codes:

void loop()

{
  if (flag == true)
  {
    display.setCursor(0, 0);
    for (int r=0; r<8;r++)
    {
      byte y = buf[r];
      display.clearDisplay();
      display.setTextSize(1);
      display.setTextColor(WHITE);
      // display.setCursor(0, 0);
      display.print(y);
      display.display();
    }
    delay(1000);
    flag == false;
  }
}

Thanks now its working perfectly.

pert:
Well, first of all, do you really need to record the run time to the second? That seems a bit excessive to me.

There is also the idea of adding components to allow you to detecting the loss of the Arduino board’s power and writing the data to EEPROM only then. That will require a backup power source. I believe doing this with a capacitor has been discussed quite a few times here on the forum.

If that’s not to your liking, there’s the concept of wear leveling I mentioned, where you rotate between multiple addresses. That will multiply the life expectancy.

I have made some changes in my Engine hour meter:-(successful)

#include <EEPROM.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_Address 0x3C
Adafruit_SSD1306 oled(1);
#include "Wire.h"
#define WIDTH     128
#define HEIGHT     64
#define NUM_PAGE    8
#define ONE_WIRE_BUS A0
long lastTime = 0;

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16




const uint8_t EngineCommand = 8;
float temp;


int EventState = 0;
int addr_secnd = 0;
int addr_Minute = 1;
int addr_hrs1 = 2;
int addr_hrs2 = 3;
int addr_hrs3 = 4;
int addr_hrs4 = 5;
int addr_hrs5 = 6;

int secnd = 0;
int Minute = 0;
int hrs1 = 0;
int hrs2 = 0;
int hrs3 = 0;
int hrs4 = 0;
int hrs5 = 0;
int value_secnd;
int value_Minute;
int value_hrs1;
int value_hrs2;
int value_hrs3;
int value_hrs4;
int value_hrs5;
int x6;
int x7;
int x8;
long seconds = EEPROM.read(addr_secnd);
long minutes = EEPROM.read(addr_Minute);
long hours = EEPROM.read(addr_hrs2);

void setup() {
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);

  Serial.begin(9600);
  Wire.begin();
  pinMode(EngineCommand, INPUT);

}



void loop() {
  display();
  if (digitalRead(EngineCommand) == LOW) 
  {
    EventState = 0;
    if (millis() - lastTime > 0)
    {
      seconds++;
      lastTime = millis();
    }
    if (seconds > 59) 
    {

      minutes++;
      seconds = 0;
      
    }
    if (minutes > 59) 
    {

      hours++;
      minutes = 0;
    }
    Serial.print(hours);
    Serial.print(":");
    Serial.print(minutes);
    Serial.print(":");
    Serial.println(seconds);

    delay(1000);
  }

  else 
  {
    if (EventState < 1)
    {
      EEPROM.update(addr_secnd, seconds);
      EEPROM.update(addr_Minute, minutes);
      EEPROM.update(addr_hrs2, hours);
      Serial.println(EEPROM.read(addr_hrs2));
      Serial.print(EEPROM.read(addr_Minute));
      Serial.print(EEPROM.read(addr_secnd));
      EventState++;
    }
  }
}
void display()
{
  
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE, BLACK);
  oled.setCursor(0, 0);
  oled.print((hours));//,":",(minutes));
  oled.print(":");
  oled.print((minutes));//,":",(minutes));
  oled.print(":");
  oled.print((seconds));//,":",(minutes));
  oled.display();
}

As per this program, when the engine get ON counting will start at the time of Engine OFF present working hours will store EEPROM . Once vehicle key switched Off and On meter counting will start from the last working hour and its working fine.

I need some help from the forum, how can apply millis() in place of delay().?

I need some help from the forum, how can apply millis() in place of delay().?

{sigh} Take a look at the blink without delay example in the IDE.

TheMemberFormerlyKnownAsAWOL:
{sigh} Take a look at the blink without delay example in the IDE.

i t

TheMemberFormerlyKnownAsAWOL:
{sigh} Take a look at the blink without delay example in the IDE.

I tried to make a program but it was not successful,Because EEPROM writing continuously along with hour meter counting.Please help me to find out mistake.

This is my program:-

#include <EEPROM.h>
#include <Wire.h>
#include <Adafruit_GFX.h>////////////////oled
#include <Adafruit_SSD1306.h>////////////oled

#include <OneWire.h>/////////////////////Temp sensor
#include <DallasTemperature.h>///////////Temp sensor
#define ONE_WIRE_BUS A0//////////////////Temp sensor
OneWire oneWire(ONE_WIRE_BUS);//////////Temp sensor
DallasTemperature sensors(&oneWire);////Temp sensor
#define ONE_WIRE_BUS A0////////////////Temp sensor

#define OLED_Address 0x3C///////////////oled
Adafruit_SSD1306 oled(1);///////////////oled
//#include "Wire.h"
#define WIDTH     128//////////////////oled
#define HEIGHT     64/////////////////oled
#define NUM_PAGE    8/////////////////oled



#define NUMFLAKES 10/////////////////oled
#define XPOS 0///////////////////////oled
#define YPOS 1///////////////////////oled
#define DELTAY 2///////////////////oled
#define LOGO16_GLCD_HEIGHT 16///////oled
#define LOGO16_GLCD_WIDTH  16//////oled




const uint8_t EngineCommand = 8;
float temp;
unsigned long time_now = 0;

int EventState = 0;
int addr_secnd = 0;
int addr_Minute = 1;
int addr_hrs1 = 2;
int addr_hrs2 = 3;
int addr_hrs3 = 4;
int addr_hrs4 = 5;
int addr_hrs5 = 6;

int secnd = 0;
int Minute = 0;
int hrs1 = 0;
int hrs2 = 0;
int hrs3 = 0;
int hrs4 = 0;
int hrs5 = 0;
int value_secnd;
int value_Minute;
int value_hrs1;
int value_hrs2;
int value_hrs3;
int value_hrs4;
int value_hrs5;
int x6;
int x7;
int x8;
int period = 1000;

unsigned long previousMillis = 0;
unsigned long currentMillis;

long lastTime = 500;
long seconds = EEPROM.read(addr_secnd);
long minutes = EEPROM.read(addr_Minute);
long hours = EEPROM.read(addr_hrs2);

void setup() 
{
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
  sensors.begin();
  Serial.begin(9600);
  Wire.begin();
  pinMode(EngineCommand, INPUT);

}



void loop() {
     display();
     currentMillis=millis();
 if (currentMillis-previousMillis>period )
 {
   
   previousMillis = currentMillis;
  
  if (digitalRead(EngineCommand) == LOW) 
  {
    EventState = 0;
    if (millis() - lastTime > 0)
    {
      seconds++;
      lastTime = millis();
    }
    if (seconds > 59) 
    {

      minutes++;
      seconds = 0;
      
    }
    if (minutes > 59) 
    {

      hours++;
      minutes = 0;
    }
    Serial.print(hours);
    Serial.print(":");
    Serial.print(minutes);
    Serial.print(":");
    Serial.println(seconds);
    /*time_now = millis();
while(millis() < time_now + period){
        //wait approx. [period] ms
    }*/
    //delay(1000);
  }
 }


  else 
  {
    if (EventState < 1)
    {
      EEPROM.update(addr_secnd, seconds);
      EEPROM.update(addr_Minute, minutes);
      EEPROM.update(addr_hrs2, hours);
      Serial.print(EEPROM.read(addr_hrs2));
      Serial.print(EEPROM.read(addr_Minute));
      Serial.println(EEPROM.read(addr_secnd));
      EventState++;
    }
  }
}

void display()
{
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE, BLACK);
  oled.setCursor(0, 0);
  oled.print((hours));//,":",(minutes));
  oled.print(":");
  oled.print((minutes));//,":",(minutes));
  oled.print(":");
  oled.print((seconds));//,":",(minutes));
  oled.setCursor(0, 8);
  oled.print((temp));
  oled.display();
}

while(millis() < time_now + period)Did you even look at the blink without delay code?

https://www.baldengineer.com/blink-without-delay-explained.html

jremington: https://www.baldengineer.com/blink-without-delay-explained.html

Thanks.

TheMemberFormerlyKnownAsAWOL:

while(millis() < time_now + period)

Did you even look at the blink without delay code?

Sorry.By mistake that line i have not removed from the post.

Now i have done some changes millis() added.
code is here:-

#include <EEPROM.h>
#include <Wire.h>
#include <Adafruit_GFX.h>////////////////oled
#include <Adafruit_SSD1306.h>////////////oled

#include <OneWire.h>/////////////////////Temp sensor
#include <DallasTemperature.h>///////////Temp sensor
#define ONE_WIRE_BUS A0//////////////////Temp sensor
OneWire oneWire(ONE_WIRE_BUS);//////////Temp sensor
DallasTemperature sensors(&oneWire);////Temp sensor
#define ONE_WIRE_BUS A0////////////////Temp sensor

#define OLED_Address 0x3C///////////////oled
Adafruit_SSD1306 oled(1);///////////////oled
//#include "Wire.h"
#define WIDTH     128//////////////////oled
#define HEIGHT     64/////////////////oled
#define NUM_PAGE    8/////////////////oled



#define NUMFLAKES 10/////////////////oled
#define XPOS 0///////////////////////oled
#define YPOS 1///////////////////////oled
#define DELTAY 2///////////////////oled
#define LOGO16_GLCD_HEIGHT 16///////oled
#define LOGO16_GLCD_WIDTH  16//////oled




const uint8_t EngineCommand = 8;
float temp;
unsigned long time_now = 0;

int EventState = 0;
int addr_secnd = 0;
int addr_Minute = 1;
int addr_hrs1 = 2;
int addr_hrs2 = 3;
int addr_hrs3 = 4;
int addr_hrs4 = 5;
int addr_hrs5 = 6;

int secnd = 0;
int Minute = 0;
int hrs1 = 0;
int hrs2 = 0;
int hrs3 = 0;
int hrs4 = 0;
int hrs5 = 0;
int value_secnd;
int value_Minute;
int value_hrs1;
int value_hrs2;
int value_hrs3;
int value_hrs4;
int value_hrs5;
int x6;
int x7;
int x8;
int period = 100;

unsigned long previousMillis = 0;
unsigned long currentMillis;

long lastTime = 0;
long seconds = EEPROM.read(addr_secnd);
long minutes = EEPROM.read(addr_Minute);
long hours = EEPROM.read(addr_hrs2);

void setup()
{
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
  sensors.begin();
  Serial.begin(9600);
  Wire.begin();
  pinMode(EngineCommand, INPUT);

}



void loop() {
     display();
     currentMillis=millis();
 if (currentMillis-previousMillis>period )
 {
   
   previousMillis = currentMillis;
 
  if (digitalRead(EngineCommand) == LOW)
  {
    EventState = 0;
    if (millis() - lastTime > 0)
    {
      seconds++;
      lastTime = millis();
    }
    if (seconds > 59)
    {

      minutes++;
      seconds = 0;
     
    }
    if (minutes > 59)
    {

      hours++;
      minutes = 0;
    }
    Serial.print(hours);
    Serial.print(":");
    Serial.print(minutes);
    Serial.print(":");
    Serial.println(seconds);
    
  }
 }


 
 if (digitalRead(EngineCommand) == HIGH)
  {
    if (EventState < 1)
    {
      EEPROM.update(addr_secnd, seconds);
      EEPROM.update(addr_Minute, minutes);
      EEPROM.update(addr_hrs2, hours);
      Serial.print(EEPROM.read(addr_hrs2));
      Serial.print(EEPROM.read(addr_Minute));
      Serial.println(EEPROM.read(addr_secnd));
      EventState++;
    }
  }
}

void display()
{
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE, BLACK);
  oled.setCursor(0, 0);
  oled.print((hours));//,":",(minutes));
  oled.print(":");
  oled.print((minutes));//,":",(minutes));
  oled.print(":");
  oled.print((seconds));//,":",(minutes));
  oled.setCursor(0, 8);
  oled.print((temp));
  oled.display();
}

Now its working.But there is a problem,when i add display() loop, in the main loop() Hour counting delayed by the seconds and gradulay its increasing.
First i think counting,delayed due to the reason i was used delay() function.But now i have replaced millis() in place of delay() but problem is not solved.

Note:-if i have removed the display() loop from main hours counter working normaly.Please help to over come this problem

The condition should be “>= period”, and instead of “previousMillis = currentMillis”, it should be “previousMillis += period”

TheMemberFormerlyKnownAsAWOL:
The condition should be “>= period”, and instead of “previousMillis = currentMillis”, it should be “previousMillis += period”

currentMillis=millis();
 if (currentMillis-previousMillis>=period )
 {
   
   previousMillis += period;

Changes have been done.But there is no much changes in counting speed , when i change the period’s value 1000 to 100ms;

If i remove the display() loop,changes in the speed is understandable.

Here is my code:-

#include <EEPROM.h>
#include <Wire.h>
#include <Adafruit_GFX.h>////////////////oled
#include <Adafruit_SSD1306.h>////////////oled

#include <OneWire.h>/////////////////////Temp sensor
#include <DallasTemperature.h>///////////Temp sensor
#define ONE_WIRE_BUS A0//////////////////Temp sensor
OneWire oneWire(ONE_WIRE_BUS);//////////Temp sensor
DallasTemperature sensors(&oneWire);////Temp sensor
#define ONE_WIRE_BUS A0////////////////Temp sensor

#define OLED_Address 0x3C///////////////oled
Adafruit_SSD1306 oled(1);///////////////oled
//#include "Wire.h"
#define WIDTH     128//////////////////oled
#define HEIGHT     64/////////////////oled
#define NUM_PAGE    8/////////////////oled



#define NUMFLAKES 10/////////////////oled
#define XPOS 0///////////////////////oled
#define YPOS 1///////////////////////oled
#define DELTAY 2///////////////////oled
#define LOGO16_GLCD_HEIGHT 16///////oled
#define LOGO16_GLCD_WIDTH  16//////oled




const uint8_t EngineCommand = 8;
float temp;
unsigned long time_now = 0;

int EventState = 0;
int addr_secnd = 0;
int addr_Minute = 1;
int addr_hrs1 = 2;
int addr_hrs2 = 3;
int addr_hrs3 = 4;
int addr_hrs4 = 5;
int addr_hrs5 = 6;

int secnd = 0;
int Minute = 0;
int hrs1 = 0;
int hrs2 = 0;
int hrs3 = 0;
int hrs4 = 0;
int hrs5 = 0;
int value_secnd;
int value_Minute;
int value_hrs1;
int value_hrs2;
int value_hrs3;
int value_hrs4;
int value_hrs5;
int x6;
int x7;
int x8;

int period = 1000;
unsigned long previousMillis = 0;
unsigned long currentMillis;

long lastTime = 0;
long seconds = EEPROM.read(addr_secnd);
long minutes = EEPROM.read(addr_Minute);
long hours = EEPROM.read(addr_hrs2);

void setup()
{
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
  sensors.begin();
  Serial.begin(9600);
  Wire.begin();
  pinMode(EngineCommand, INPUT);

}



void loop() {
     display();
     currentMillis=millis();
 if (currentMillis-previousMillis>=period )
 {
   
   previousMillis += period;
 
  if (digitalRead(EngineCommand) == LOW)
  {
    EventState = 0;
    if (millis() - lastTime > 0)
    {
      seconds++;
      lastTime = millis();
    }
    if (seconds > 59)
    {

      minutes++;
      seconds = 0;
     
    }
    if (minutes > 59)
    {

      hours++;
      minutes = 0;
    }
    Serial.print(hours);
    Serial.print(":");
    Serial.print(minutes);
    Serial.print(":");
    Serial.println(seconds);
    
  }
 }


 
 if (digitalRead(EngineCommand) == HIGH)
  {
    if (EventState < 1)
    {
      EEPROM.update(addr_secnd, seconds);
      EEPROM.update(addr_Minute, minutes);
      EEPROM.update(addr_hrs2, hours);
      Serial.print(EEPROM.read(addr_hrs2));
      Serial.print(EEPROM.read(addr_Minute));
      Serial.println(EEPROM.read(addr_secnd));
      EventState++;
    }
  }

}

void display()
{
 
  
 sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE, BLACK);
  oled.setCursor(0, 0);
  oled.print((hours));//,":",(minutes));
  oled.print(":");
  oled.print((minutes));//,":",(minutes));
  oled.print(":");
  oled.print((seconds));//,":",(minutes));
  oled.setCursor(0, 8);
  oled.print((temp));
  oled.display();

}

Changes have been done.But there is no much changes in counting speed , when i change the period's value 1000 to 100ms; If i remove the display() loop,changes in the speed is understandable.

display() is a blocking function call, and if it takes more time than "period" it will control the timing of the count. You can verify this by adding some time checks to the function.

void display()
{
  unsigned long startTime = millis();
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE, BLACK);
  oled.setCursor(0, 0);
  oled.print((hours));//,":",(minutes));
  oled.print(":");
  oled.print((minutes));//,":",(minutes));
  oled.print(":");
  oled.print((seconds));//,":",(minutes));
  oled.setCursor(0, 8);
  oled.print((temp));
  oled.display();
  Serial.print("Function Time = ")
  Serial.println(millis() - startTime);
}

cattledog: display() is a blocking function call, and if it takes more time than "period" it will control the timing of the count. You can verify this by adding some time checks to the function.

void display()
{
  unsigned long startTime = millis();
  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setTextColor(WHITE, BLACK);
  oled.setCursor(0, 0);
  oled.print((hours));//,":",(minutes));
  oled.print(":");
  oled.print((minutes));//,":",(minutes));
  oled.print(":");
  oled.print((seconds));//,":",(minutes));
  oled.setCursor(0, 8);
  oled.print((temp));
  oled.display();
  Serial.print("Function Time = ")
  Serial.println(millis() - startTime);
}

Yes sir,How can over come this problem. Please help me solve out this problem.