Project

Dependencies:   Hotboards_keypad TextLCD eeprom

Files at this revision

API Documentation at this revision

Comitter:
shivanandgowdakr
Date:
Mon Sep 16 14:05:54 2019 +0000
Parent:
0:194ff03a2e6a
Commit message:
Time Controlled Switch Display

Changed in this revision

eeprom.lib Show annotated file Show diff for this revision Revisions of this file
i2ceeprom.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 194ff03a2e6a -r 1894419d5def eeprom.lib
--- a/eeprom.lib	Tue Oct 23 08:12:53 2018 +0000
+++ b/eeprom.lib	Mon Sep 16 14:05:54 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/Exultsoft1/code/eeprom/#78ca3fcb8db1
+http://developer.mbed.org/users/bborredon/code/eeprom/#925096a4c7f0
diff -r 194ff03a2e6a -r 1894419d5def i2ceeprom.cpp
--- a/i2ceeprom.cpp	Tue Oct 23 08:12:53 2018 +0000
+++ b/i2ceeprom.cpp	Mon Sep 16 14:05:54 2019 +0000
@@ -1,19 +1,46 @@
 
-
-// Example
-
-#include <string>
 #include "mbed.h"
+#include <string>
 #include "eeprom.h"
+#include "i2ceeprom.h"
 
-#define EEPROM_ADDR 0x02   // I2C EEPROM address is 0x00
+#define EEPROM_ADDR 0x0   // I2c EEPROM address is 0x00
 
-#define SDA D14            // I2C SDA pin
+#define SDA D14           // I2C SDA pin
 #define SCL D15           // I2C SCL pin
 
 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
 
+#define MB_ID 0x00
+#define NO_OF_DEV 0x01
+#define DEV_1_ID 0x02
+#define DEV_1_ST 0x03
+#define DEV_1_VAL 0x04
+#define DEV_2_ID 0x05
+#define DEV_2_ST 0x06
+#define DEV_2_VAL 0x07
+#define DEV_3_ID 0x08
+#define DEV_3_VAL 0x09
+#define DEV_4_ID 0x0A
+#define DEV_4_ST 0x0B
+#define DEV_4_VAL 0x0C
+
+int mb_ID = 0x00;
+int NOno_of_dev = 0x00;
+int dev_1_id = 0x00;
+int dev_1_st = 0x00;
+int dev_1_val = 0x00;
+int dev_2_id = 0x00;
+int dev_2_st = 0x00;
+int dev_2_val = 0x00;
+int dev_3_id = 0x00;
+int dev_3_st = 0x00;
+int dev_3_val = 0x00;
+int dev_4_id = 0x00;
+int dev_5_st = 0x00;
+int dev_6_val = 0x00;
+
 extern float G_time;
 extern float Y_time;
 extern float R_time;
@@ -34,15 +61,15 @@
 
 void StoreCurrentMode(int32_t idata)
 {
-  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128);  // 24C64 eeprom with sda = p9 and scl = p10  
+  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C32);  // 24C64 eeprom with sda = p9 and scl = p10  
   eeprom_size = ep.getSize();
-  max_size = MIN(eeprom_size,256);
-  ep.write((uint32_t)(eeprom_size - 200),(int32_t)idata); // long write at address eeprom_size - 12
+  max_size = MAX(eeprom_size,256);
+  ep.write(10,(int32_t)idata); // long write at address eeprom_size - 12
   if(ep.getError() != 0)
     myerror(ep.getErrorMessage());
-//    printf("\n");    
-    ep.read((eeprom_size - 12),(int32_t&)idata);
-   // printf("TransDC Read %d\r\n",idata);
+    printf("\n");    
+    ep.read(10,(int32_t&)idata);
+//   printf("TransDC Read %d\r\n",idata);
 }
 
 
@@ -50,25 +77,26 @@
 int32_t readCurrentMode()
 {
   int32_t idata;
-  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128);  // 24C64 eeprom with sda = p9 and scl = p10
+  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C32);  // 24C64 eeprom with sda = p9 and scl = p10
     eeprom_size = ep.getSize();
-  max_size = MIN(eeprom_size,256);
- ep.read((eeprom_size - 200),(int32_t&)idata);
+  max_size = MAX(eeprom_size,256);
+  printf(" Max Size =:%d\r\n",max_size);
+ ep.read(10,(int32_t&)idata);
  
  if(ep.getError() != 0)
     myerror(ep.getErrorMessage());
-//    printf("\n");
-   // printf("Trans Down Count Read %d\r\n",idata);
+   //printf("\n");
+//   printf("Trans Down Count Read %d\r\n",idata);
    return idata;
 }
 
 bool WriteCorresspondingTimes(uint32_t currentMode, float gTime,float yTime,float rTime)
 {
-  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128);  // 24C64 eeprom with sda = p9 and scl = p10
+  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C32);  // 24C64 eeprom with sda = p9 and scl = p10
   eeprom_size = ep.getSize();
-  max_size =  MIN(eeprom_size,256);
+  max_size =  MAX(eeprom_size-200,256);
   
-    uint32_t addr = eeprom_size - (currentMode*12);
+    uint32_t addr = 100*currentMode;
   ep.write(addr,(float)gTime); // float write at address eeprom_size - 8
   if(ep.getError() != 0)
     myerror(ep.getErrorMessage());
@@ -77,7 +105,7 @@
   printf("\nGreen Time : (%f) :\n",gTime);  
  
   
-  addr = eeprom_size - ((currentMode*12)-4);
+  addr = 100*currentMode +4;
   ep.write(addr,(float)yTime); // float write at address eeprom_size - 8
   if(ep.getError() != 0)
     myerror(ep.getErrorMessage());
@@ -85,7 +113,7 @@
   // Test read short, long, float
   printf("\nYellow Time : (%f) :\n",yTime);  
   
-     addr = eeprom_size - ((currentMode*12)-8);
+     addr = 100*currentMode +8;
   ep.write(addr,(float)rTime); // float write at address eeprom_size - 8
   if(ep.getError() != 0)
     myerror(ep.getErrorMessage());
@@ -100,32 +128,33 @@
 bool ReadCorresspondingTimes(uint32_t currentMode, float *gTime,float *yTime,float *rTime)
 {
   float fdata=0.0;
-  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C128);  // 24C64 eeprom with sda = p9 and scl = p10
+  EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C32);  // 24C64 eeprom with sda = p9 and scl = p10
     eeprom_size = ep.getSize();
-  max_size = MIN(eeprom_size,256);
- ep.read((eeprom_size - (currentMode*12)),(float&)fdata);
-
+    printf("Size is : %d",eeprom_size);
+  max_size = MAX(eeprom_size-200,256);
+  printf(" Here 1\r\n");
+  uint32_t addr=currentMode*100;
+  ep.read(addr,fdata);  
+  *gTime=fdata;
+  
+  fdata=0;
+  addr = 100*currentMode +4;
+//   ep.read((uint32_t)(max_size - ((currentMode*12)-4)),fdata);  
+   ep.read(addr,fdata);  
+  *yTime=fdata;
+  fdata=0;
+  addr = 100*currentMode +8;
+//   ep.read((uint32_t)(max_size - ((currentMode*12)-8)),fdata); 
+ep.read(addr,fdata);   
+  *rTime=fdata;
+  printf("1 : %f\r\n",*gTime);
+  printf("2 : %f\r\n",*yTime);
+  printf("3 : %f\r\n",*rTime);
+   
  if(ep.getError() != 0)
     myerror(ep.getErrorMessage());
-//    printf("\n");
-   // printf("Trans Down Count Read %d\r\n",idata);
-  *gTime=fdata;
-  fdata=0.0;
-  ep.read((eeprom_size - (currentMode*12)-4),(float&)fdata);
+
  
- if(ep.getError() != 0)
-    myerror(ep.getErrorMessage());
-//    printf("\n");
-   // printf("Trans Down Count Read %d\r\n",idata);
-  *yTime=fdata;
-  fdata=0.0;
-    ep.read((eeprom_size - (currentMode*12)-8),(float&)fdata);
- 
- if(ep.getError() != 0)
-    myerror(ep.getErrorMessage());
-//    printf("\n");
-   // printf("Trans Down Count Read %d\r\n",idata);
-  *rTime=fdata; 
 }
 
 
diff -r 194ff03a2e6a -r 1894419d5def main.cpp
--- a/main.cpp	Tue Oct 23 08:12:53 2018 +0000
+++ b/main.cpp	Mon Sep 16 14:05:54 2019 +0000
@@ -1,4 +1,3 @@
-
 
 #include "mbed.h"
 #include "LCDDisplay.h"
@@ -8,8 +7,7 @@
 
 // Defines the keys array with it's respective number of rows & cols,
 // and with the value of each key
-char keys[ 4 ][ 4 ] =
-{
+char keys[ 4 ][ 4 ] = {
     { '1' , '2' , '3' , 'A' },
     { '4' , '5' , '6' , 'B' },
     { '7' , '8' , '9' , 'C' },
@@ -20,22 +18,14 @@
 DigitalInOut rowPins[ 4 ] = {D4,D5,D6,D7 };
 // Defines the pins connected to the cols
 DigitalInOut colPins[ 4 ] = { D8,D9,D10,D11};
-     //connect to the column pinouts of the keypad
+//connect to the column pinouts of the keypad
 
 Keypad keypad( makeKeymap( keys ), rowPins, colPins,4,4);
 
-DigitalIn Mode1(PC_8);
-DigitalIn Mode2(PC_6);
-DigitalIn Mode3(PC_5);
-//DigitalIn Mode4(PC_5);
-//DigitalIn Mode5(PC_8);
-//DigitalIn Mode6(PC_6);
 
 bool PasswordStatus=false;
 int mode=0;
-DigitalIn Start(PA_12);
-DigitalIn Stop(PA_11);
-DigitalIn Reset(PB_12);
+
 
 
 DigitalOut GreenLight(PB_1);
@@ -49,12 +39,13 @@
 
 
 
-uint32_t Current_Mode=0;
+uint32_t Current_Mode=1;
 
 float G_time=0;
 float Y_time=0;
 float R_time=0;
 
+
 uint8_t  StartButtonPressed=0;
 uint8_t  StopButtonPressed=0;
 uint8_t  ReStartButtonPressed=0;
@@ -63,28 +54,23 @@
 //Thread EveryOneSec;
 
 void keypadEvent(KeypadEvent key);
-bool ReadEachLightTime(int mode,char *mmss);
-bool ReadAllTimesofEachMode(int MODE,char *Greentime,char *Yellowtime,char *Redtime);
+bool ReadEachLightTime(uint32_t mode,char *mmss);
+bool ReadAllTimesofEachMode(uint32_t MODE,char *Greentime,char *Yellowtime,char *Redtime);
 void ExtractTimesinSecs(char *greentime,char *yellowtime,char *redtime,float *grntim,float *yeltim,float *redtim);
-void SaveTimes(int Mode,float GreenTime,float YellowTime,float RedTime);
+void SaveTimes(uint32_t Mode,float GreenTime,float YellowTime,float RedTime);
 void CalculateTimeElapsed(float TimeElapsed, char *TimeStr);
 bool PasswordAcceptance();
 int ModeSelectTochange();
+ void Get_Time_Elapsed_after_Start(float timeInSec, char * str);
 void fn(char rkey);
 int main()
 {
-  bool start=false;
-  Mode1.mode(PullUp);
-  Mode2.mode(PullUp);
-  Mode3.mode(PullUp);
-//  Mode4.mode(PullUp);
-//  Mode5.mode(PullUp);
-//  Mode6.mode(PullUp);
-  bool lcdflag=true;
-  Start.mode(PullUp);
-  Stop.mode(PullUp);
-  Reset.mode(PullUp);
-   
+    bool start=false;
+  
+    bool lcdflag=true;
+    
+    char Timestr[10]={'\0'};
+    char Buf[17]={'\0'};
     float timeElapsed=0;
     char buff[6]= {'\0'};
     char Buffer[17]= {'\0'};
@@ -97,258 +83,260 @@
     wait(1);
     Clear_LCD();
     //Current_Mode=1;
-     Display_LCD(0,0,"Select Mode Or");
-     Display_LCD(0,1,"Press Start ");
-     G_time=20;
-     Y_time=5;
-     R_time=10;
+//    Last_Saved_Mode();
+    Display_LCD(0,0,"Select Mode Or");
+    Display_LCD(0,1,"Press Start ");
+    G_time=20;
+    Y_time=5;
+    R_time=10;
     char key;
+
+    
+    Current_Mode = readCurrentMode();
+    
+    //WriteCorresspondingTimes(1, 10,20,30);
+//    ReadCorresspondingTimes(1,&G_time,&Y_time,&R_time);
+
+    
+    printf("Current Mode is  %d \r\n", Current_Mode);
+    
     while(1) {
         
-        
         key=keypad.getKey();
-        if(key)
-        {
-          if(key=='*')
-          {
-            PasswordStatus=PasswordAcceptance();  
-          }
-          if(PasswordStatus==true)
-          {
-              PasswordStatus=false;
-             mode= ModeSelectTochange();
-             if(mode>=1 &&  mode <=6)
-             {    
-               fn((char)(mode+0x30));
-              mode=0;  
-             }
-             else
-             {
-                Display_LCD(0,0," Invalid Mode   ");
-                Display_LCD(0,1,"Mode b/w 1-6   ");
-               wait(2);
-               
-               Clear_LCD();
-               Display_LCD(0,0,"Select Mode Or");
-               Display_LCD(0,1,"Press Start ");
-                    
-             }
-          }
-          
-         else if(key=='A')
-         {
-           printf("Started \r\n");
-             StartButtonPressed=1;
-             StopButtonPressed=0;
-             ReStartButtonPressed=0;
-             printf("Started ************ %d \r\n",StartButtonPressed);
-             printf("Started ############## %d \r\n",StopButtonPressed);
-             printf("Started 88888888888888%d \r\n",ReStartButtonPressed);
-             timer.start();
-          
-         }
-         
-         else if(key=='B')
-         {
-          StartButtonPressed=0;
-             StopButtonPressed=1;
-             ReStartButtonPressed=0;
-         
-         printf("Stopped \r\n");
-         wait(0.2);
-         }
-         else if(key=='C')
-         {
-             StartButtonPressed=0;
-             StopButtonPressed=0;
-             ReStartButtonPressed=1;
-             timer.stop();
-             printf("Reset \r\n");
-             wait(0.2);
-         }
-         
-         else if(key=='D')
-         {
-          Clear_LCD();
-          Display_LCD(0,0,"Choose Mode");
-          wait(0.5);
-          char tempkey=keypad.waitForKey();
-          if(tempkey>=0x31 && tempkey<=0x36)
-          {
-              char Buff[20]={'\0'};
-              sprintf(Buff,"Current Mode %c",tempkey);
-              Display_LCD(0,1,Buff);
-              Current_Mode=(int)(tempkey-0x30);
-              wait(1);
-              Clear_LCD();
-              
-              }
-              else
-              {
-                  Display_LCD(0,0,"Invld Mod Entrd");
-                  wait(1);
-                  Clear_LCD();
-                  
-              }
-         }
-         else
-         {}
-          
+        
+        printf("Key is :%c\r\n",key);
+        if(key) {
+            if(key=='*') {
+                PasswordStatus=PasswordAcceptance();
+            }
+            if(PasswordStatus==true) {
+                PasswordStatus=false;
+                mode= ModeSelectTochange();
+                if(mode>=1 &&  mode <=6) {
+                    fn((char)(mode+0x30));
+                    mode=0;
+                } else {
+                    Display_LCD(0,0," Invalid Mode   ");
+                    Display_LCD(0,1," Mode b/w 1-6   ");
+                    wait(2);
+
+                    Clear_LCD();
+                    Display_LCD(0,0,"Select Mode Or");
+                    Display_LCD(0,1,"Press Start ");
+
+                }
+            }
+
+            else if(key=='A') {
+                printf("Started \r\n");
+                StartButtonPressed=1;
+                StopButtonPressed=0;
+                ReStartButtonPressed=0;
+                printf("Started \r\n");
+                timer.start();
+
+            }
+
+            else if(key=='B') {
+                StartButtonPressed=0;
+                StopButtonPressed=1;
+                ReStartButtonPressed=0;
+
+                printf("Stopped \r\n");
+                wait(0.2);
+            } 
+            
+            else if(key=='C') {
+                StartButtonPressed=0;
+                StopButtonPressed=0;
+                ReStartButtonPressed=1;
+                timer.stop();
+                printf("Reset \r\n");
+                wait(0.2);
+            }
+
+            else if(key=='D') {
+                Clear_LCD();
+                Display_LCD(0,0,"Choose Mode");
+                wait(0.5);
+                char tempkey=keypad.waitForKey();
+                if(tempkey>=0x31 && tempkey<=0x36) {
+                    char Buff[20]= {'\0'};
+                    sprintf(Buff,"Current Mode %c",tempkey);
+                    Display_LCD(0,1,Buff);
+                    Current_Mode=(int)(tempkey-0x30);
+                    StoreCurrentMode(Current_Mode);
+                    wait(1);
+                    Clear_LCD();
+
+                } else {
+                    Display_LCD(0,0,"Invld Mod Entrd");
+                    wait(1);
+                    Clear_LCD();
+
+                }
+            } else
+                {}
+
         }
 
-        
+
 //        if(Mode1==0)
- if(Current_Mode==1)
-        {
-            printf("Am here in Mode 1\r\n");
-            G_time=20;
-            Y_time=5;
-            R_time=10;
-         
-//          ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
-            printf("Current MOde  1 \r\n");
+        if(Current_Mode==1) {
+//            printf("Am here in Mode 1\r\n");
+           //  G_time=20;
+//            Y_time=5;
+//            R_time=10;
+
+            ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+//            printf(" G_time %f, Y Time %f R_time %f :",G_time,Y_time,R_time);
+//            printf("Current MOde  1 \r\n");
 //            Display_LCD(0,1,"Mode: 1");
+
+
             Y_time=Y_time+G_time;
             R_time=R_time+Y_time;
             wait(0.2);
-         }
-         
+        }
+
 //          if(Mode2==0)
- if(Current_Mode==2)
-        {
-         
-            G_time=2;
-            Y_time=5;
-            R_time=1;
-            Current_Mode=2;
-//          ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+        if(Current_Mode==2) {
+
+          //   G_time=2;
+//            Y_time=5;
+//            R_time=1;
+           Current_Mode=2;
+            ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+            
             printf("Current MOde  2 \r\n");
 //            Display_LCD(0,1,"Mode: 2");
             Y_time=Y_time+G_time;
             R_time=R_time+Y_time;
             wait(0.1);
-         }
-         
+        }
+
 //         if(Mode3==0)
- if(Current_Mode==3)
-        {
-         
-            G_time=12;
-            Y_time=5;
-            R_time=10;
+        if(Current_Mode==3) {
+
+          //   G_time=12;
+//            Y_time=5;
+//            R_time=10;
             Current_Mode=3;
-//          ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+           ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
             printf("Current MOde  3 \r\n");
 //            Display_LCD(0,1,"Mode: 3");
             Y_time=Y_time+G_time;
             R_time=R_time+Y_time;
             wait(0.1);
-         }
-         
-         
-      //  if(Mode4==0)
-      if(Current_Mode==4)
-        {
-         
-            G_time=20;
-            Y_time=5;
-            R_time=10;
+        }
+
+
+        //  if(Mode4==0)
+        if(Current_Mode==4) {
+
+            //  G_time=20;
+//            Y_time=5;
+//            R_time=10;
             Current_Mode=4;
-//            ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+            ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
             printf("Current MOde  1 \r\n");
             Display_LCD(0,1,"Mode: 4");
             Y_time=Y_time+G_time;
             R_time=R_time+Y_time;
             wait(0.2);
-         }
-//         
-            if(Current_Mode==5)
-        {
-         
-            G_time=2;
-            Y_time=5;
-            R_time=1;
+        }
+//
+        if(Current_Mode==5) {
+
+           // G_time=2;
+//            Y_time=5;
+//            R_time=1;
             Current_Mode=5;
-            printf("Current MOde  2 \r\n");
-//            ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
-           Display_LCD(0,1,"Mode: 5");
+//            printf("Current MOde  2 \r\n");
+            ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+            Display_LCD(0,1,"Mode: 5");
             Y_time=Y_time+G_time;
             R_time=R_time+Y_time;
             wait(0.2);
-         }
-//         
+        }
+//
 //         if(Mode6==0)
-if(Current_Mode==6)
-        {
-         
-            G_time=12;
-            Y_time=5;
-            R_time=10;
+        if(Current_Mode==6) {
+
+           // G_time=12;
+//            Y_time=5;
+//            R_time=10;
             Current_Mode=3;
-            printf("Current MOde  3 \r\n");
-//            ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
+//            printf("Current MOde  3 \r\n");
+           ReadCorresspondingTimes(Current_Mode,&G_time,&Y_time,&R_time);
             Display_LCD(0,1,"Mode: 6");
             Y_time=Y_time+G_time;
             R_time=R_time+Y_time;
             wait(0.2);
-         }
+        }
 
 
-         if(Start==0)
-         {
-             printf("Started \r\n");
-             StartButtonPressed=1;
-             StopButtonPressed=0;
-             ReStartButtonPressed=0;
-             printf("Started ************ %d \r\n",StartButtonPressed);
-             printf("Started ############## %d \r\n",StopButtonPressed);
-             printf("Started 88888888888888%d \r\n",ReStartButtonPressed);
-            
-             timer.start();
-                         
-         }
-          if(Stop==0)
-         {
-             StartButtonPressed=0;
-             StopButtonPressed=1;
-             ReStartButtonPressed=0;
-         
-         printf("Stopped \r\n");
-         wait(0.2);
-         
-         }
-         
-         if(Reset==0)
-         {
-             StartButtonPressed=0;
-             StopButtonPressed=0;
-             ReStartButtonPressed=1;
-             timer.stop();
-             printf("Reset \r\n");
-             wait(0.2);
-         }
-         
-         
-        if(StartButtonPressed==1 && StopButtonPressed==0 && ReStartButtonPressed==0 ) { 
-         printf("  Read Time %f\r\n",timer.read()); //while
+       // if(Start==0) {
+//            printf("Started \r\n");
+//            StartButtonPressed=1;
+//            StopButtonPressed=0;
+//            ReStartButtonPressed=0;
+//            printf("Started ************ %d \r\n",StartButtonPressed);
+//            printf("Started ############## %d \r\n",StopButtonPressed);
+//            printf("Started 88888888888888%d \r\n",ReStartButtonPressed);
+//
+//            timer.start();
+//
+//        }
+//        if(Stop==0) {
+//            StartButtonPressed=0;
+//            StopButtonPressed=1;
+//            ReStartButtonPressed=0;
+//
+//            printf("Stopped \r\n");
+//            wait(0.2);
+//
+//        }
+//
+//        if(Reset==0) {
+//            StartButtonPressed=0;
+//            StopButtonPressed=0;
+//            ReStartButtonPressed=1;
+//            timer.stop();
+//            printf("Reset \r\n");
+//            wait(0.2);
+//        }
+
+
+        if(StartButtonPressed==1 && StopButtonPressed==0 && ReStartButtonPressed==0 ) {
+            printf("  Read Time %f\r\n",timer.read()); //while
             if(timer.read()<=G_time ) {
-               
-                if(lcdflag==true)
-                {
-                  Clear_LCD();
-                  lcdflag=false;
-                 
+
+                if(lcdflag==true) {
+                    Clear_LCD();
+                    lcdflag=false;
+
                 }
+                
+                
 //                timer.start();
                 printf("  Read Time %f\r\n",timer.read());
-                Display_LCD(0,0,"Green Light    ");
+                Display_LCD(0,0,"   Green Light  ");
+                Get_Time_Elapsed_after_Start(timer.read(),Timestr);
+//                 Display_LCD(0,1,Timestr);
+                 sprintf(Buf,"      %s     ",Timestr);
+                 Display_LCD(0,1,Buf);
+                 memset(Buf,'\0',16);
                 GreenLight=0;
                 YellowLight=1;
                 RedLight=1;
-                wait(0.1);
+              
             } else if( timer.read()>G_time && timer.read()<=Y_time ) {
-                Display_LCD(0,0,"Yellow Light   ");
-                
+                Display_LCD(0,0,"  Yellow Light   ");
+                 Get_Time_Elapsed_after_Start(timer.read(),Timestr);
+                 sprintf(Buf,"      %s     ",Timestr);
+                 Display_LCD(0,1,Buf);
+                 memset(Buf,'\0',16);
                 GreenLight=1;
                 YellowLight=0;
                 RedLight=1;
@@ -356,24 +344,58 @@
                 printf("  Read Time %f\r\n",timer.read());
             }
 
-            else if( timer.read()>Y_time  && timer.read()<=R_time )
-            {
-                Display_LCD(0,0,"Red  Light    ");
+            else if( timer.read()>Y_time  && timer.read()<=R_time ) {
+                Display_LCD(0,0,"   Red  Light    ");
+                 Get_Time_Elapsed_after_Start(timer.read(),Timestr);
+//                 Display_LCD(0,1,Timestr);
+                sprintf(Buf,"      %s     ",Timestr);
+                 Display_LCD(0,1,Buf);
+                 memset(Buf,'\0',16);
                 GreenLight=1;
                 YellowLight=1;
                 RedLight=0;
                 timerred.start();
-                wait(0.1);
-                 
-                 printf("  Read Time %f\r\n",timer.read());
-            } 
+               
+
+                printf("  Read Time %f\r\n",timer.read());
+            }
+               else if( timer.read()>R_time )
+               {
+                    GreenLight=1;
+                    YellowLight=1;
+                    RedLight=1; 
+                    timeElapsed=timer.read();
+                    timer.stop();
+                     printf("Total Time  = %f\r\n",timeElapsed);
+
+            CalculateTimeElapsed(timeElapsed,buff);
+
+            sprintf(Buffer,"Total Time %s",buff);
+
+            Display_LCD(0,0,Buffer);
+            memset(Buffer,'\0',17);
+            timeElapsed=timerred.read();
+            timerred.stop();
+            CalculateTimeElapsed(timeElapsed,buff);
+            memset(Buffer,'\0',17);
+            sprintf(Buffer,"Tim af Red %s",buff);
+            Display_LCD(0,1,Buffer);
+            memset(Buffer,'\0',17);
+
+            StartButtonPressed=0;
+            StopButtonPressed=1;
+            ReStartButtonPressed=0;
+
+                   
+                }
+            
             //else if(timer.read()>R_time) {
 //                Display_LCD(0,0,"Time Lmt Excded ");
 //                GreenLight=1;
 //                YellowLight=1;
 //                RedLight=1;
 //                wait(0.2);
-//                
+//
 //
 //            }
 
@@ -383,53 +405,52 @@
         if(StartButtonPressed==0 && StopButtonPressed==1 && ReStartButtonPressed==0 ) {
             timeElapsed=timer.read();
             timer.stop();
-           
+
             printf("Total Time  = %f\r\n",timeElapsed);
-            
+
             CalculateTimeElapsed(timeElapsed,buff);
-            
+
             sprintf(Buffer,"Total Time %s",buff);
-            
+
             Display_LCD(0,0,Buffer);
             memset(Buffer,'\0',17);
             timeElapsed=timerred.read();
             timerred.stop();
-             CalculateTimeElapsed(timeElapsed,buff);
+            CalculateTimeElapsed(timeElapsed,buff);
             memset(Buffer,'\0',17);
             sprintf(Buffer,"Tim af Red %s",buff);
             Display_LCD(0,1,Buffer);
             memset(Buffer,'\0',17);
-            
+
             wait(0.1);
-            
-           // /******************************************/
-//               ReStartButtonPressed=1;
-//                StartButtonPressed=0;
-//            StopButtonPressed=0;
+            /*******************************************
+            * If you want to use Reset Button Comment these lines
+            * Presently it is with auto reset
+             ******************************************/
+               ReStartButtonPressed=1;
+                StartButtonPressed=0;
+            StopButtonPressed=0;
 //                /******************************************/
         }
         if(StartButtonPressed==0 && StopButtonPressed==0 && ReStartButtonPressed==1 ) {
 
-           
-            Display_LCD(0,0,"Done Resetting");
+//            Display_LCD(0,0,"Done Resetting");
             StartButtonPressed=0;
             StopButtonPressed=0;
             ReStartButtonPressed=0;
-            Clear_LCD();
-            
-          
+//            Clear_LCD();
+
         }
-       if(StartButtonPressed==0 && StopButtonPressed==0 && ReStartButtonPressed==0 ) {
+        if(StartButtonPressed==0 && StopButtonPressed==0 && ReStartButtonPressed==0 ) {
             GreenLight=1;
             YellowLight=1;
             RedLight=1;
             timer.reset();
             timerred.reset();
-            
 //            printf(" Last Line\r\n");
-            Display_LCD(0,0,"Select Mode Or");
-            Display_LCD(0,1,"Press Start ");
-           
+           // Display_LCD(0,0,"Select Mode Or");
+//            Display_LCD(0,1,"Press Start ");
+
             lcdflag=true;
         }
 
@@ -441,122 +462,108 @@
 {
     char rkey;
     char Str[5]= {'\0'};
-    char Star[5]={'\0'};
-    char text[5]={'\0'};
-    char  GreenTime[6]={'\0'};
-    char  YellowTime[6]={'\0'};
-    char  RedTime[6]={'\0'};
+    char Star[5]= {'\0'};
+    char text[5]= {'\0'};
+    char  GreenTime[6]= {'\0'};
+    char  YellowTime[6]= {'\0'};
+    char  RedTime[6]= {'\0'};
     bool Staus=false;
-              rkey=keypad.waitForKey();          
+    rkey=keypad.waitForKey();
+
+    switch(rkey) {
+
+        case '1':
+
+        {
+            Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                SaveTimes(1,GTIME,YTIME,RTIME);
+                printf(" Times %f  %f  %f \r\n",GTIME,YTIME,RTIME);
+            }
+            Staus=false;
+        }
+        break;
+        case '2': {
+            Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                printf(" Times %f  %f  %f \r\n",GTIME,YTIME,RTIME);
+                SaveTimes(2,GTIME,YTIME,RTIME);
+            }
+            Staus=false;
+        }
+        break;
+        case '3': {
+            Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                SaveTimes(3,GTIME,YTIME,RTIME);
+            }
+            Staus=false;
+        }
 
-                        switch(rkey)
-                        {
-                                                  
-                                    case '1':
-                
-                                      {
-                                        Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-                                           SaveTimes(1,GTIME,YTIME,RTIME);
-                                        }
-                                        Staus=false;
-                                        }
-                                        break;
-                                    case '2':
-                                      {       
-                                        Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-                                           SaveTimes(2,GTIME,YTIME,RTIME);
-                                        }
-                                        Staus=false;
-                                       }
-                                        break;
-                                    case '3':
-                                        {
-                                        Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-                                           SaveTimes(3,GTIME,YTIME,RTIME);
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                                    case '4':
-                                        {
-                                        Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-                                           SaveTimes(4,GTIME,YTIME,RTIME);
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                                    case '5':
-                                        {
-                                        Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-                                           SaveTimes(5,GTIME,YTIME,RTIME);
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                
-                                    case '6':
-                                     {
-                                        Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-                                           SaveTimes(6,GTIME,YTIME,RTIME);
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                                    default:
-                                    {
-                                        printf("No Mode\r\n");
-                                        Clear_LCD();
-                                        Display_LCD(0,0,"  InValid Mode ");
-                                        
-                                    }
-                                        
-                                        
-                            }
-                    
-          
+        break;
+        case '4': {
+            Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                SaveTimes(4,GTIME,YTIME,RTIME);
+            }
+            Staus=false;
+        }
+
+        break;
+        case '5': {
+            Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                SaveTimes(5,GTIME,YTIME,RTIME);
+            }
+            Staus=false;
+        }
+
+        break;
+
+        case '6': {
+            Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                SaveTimes(6,GTIME,YTIME,RTIME);
+            }
+            Staus=false;
+        }
+
+        break;
+        default: {
+            printf("No Mode\r\n");
+            Clear_LCD();
+            Display_LCD(0,0,"  InValid Mode ");
+        }
+    }
+
+
 }
 
-bool ReadEachLightTime(int mode,char *mmss,char *lightTimeName)
+bool ReadEachLightTime(uint32_t mode,char *mmss,char *lightTimeName)
 {
     Clear_LCD();
     char Buffer[17]= {'\0'};
     char Buffer1[17]="Entr Time Mode:";
     char Buffer2[17]="Tim MM:SS";
-    
+
     uint8_t index1=0;
     char key='\0';
     char str[6]= {'\0'};
@@ -566,8 +573,8 @@
     memset(Buffer,'\0',16);
     sprintf(Buffer,"%s %s",lightTimeName,Buffer2);
     Display_LCD(0,1,Buffer);
-    
-   wait(3);
+
+    wait(3);
     Clear_LCD();
     Display_LCD(0,0,"Press # Set ");
     Display_LCD(0,1,"Prss * to Exit ");
@@ -576,7 +583,7 @@
     if(key=='#') {
         Clear_LCD();
         Display_LCD(0,0,"MM:SS ");
-       
+        Display_LCD(0,1,"MM:SS ");
         index1=0;
         while(index1==0 ||(index1<=4 && key !='#' && key!='*')) {
             key=keypad.waitForKey();
@@ -598,26 +605,28 @@
         mmss[6]='\0';
         wait(1);
         Clear_LCD();
-        
+
         return true;
-    } else if(key=='*'){
+    } else if(key=='*') {
         Display_LCD(0,0,"Mode Not Set    ");
         Display_LCD(0,1,"Retains PrevMode");
+        wait (2);
+        Clear_LCD();
         return false;
     }
 }
 
 
-bool ReadAllTimesofEachMode(int MODE,char *Greentime,char *Yellowtime,char *Redtime)
+bool ReadAllTimesofEachMode(uint32_t MODE,char *Greentime,char *Yellowtime,char *Redtime)
 {
     bool Greenflag=false,Yellowflag=false,Redflag=false;
     Greenflag=ReadEachLightTime(MODE,Greentime,"Green");
-    
+
     if(Greenflag==true) {
-        
+
         Yellowflag=ReadEachLightTime(MODE,Yellowtime,"Yellow");
         if(Yellowflag==true) {
-           
+
             Redflag=ReadEachLightTime(MODE,Redtime,"Red");
             if(Redflag==true) {
                 return true;
@@ -653,21 +662,24 @@
     *redtim=mins*60+secs;
 }
 
-void SaveTimes(int Mode,float GreenTime,float YellowTime,float RedTime)
+void SaveTimes(uint32_t Mode,float GreenTime,float YellowTime,float RedTime)
 {
     bool flag=false;
     flag=WriteCorresspondingTimes(Mode, GreenTime,YellowTime,RedTime);
-    {
+        
         if(flag==true) {
             Clear_LCD();
-            Display_LCD(0,0," Mode Save Success");
+            Display_LCD(0,0,"    Mode Save  ");
+            Display_LCD(0,1,"     Success   ");
             wait(1);
         } else {
             Clear_LCD();
-            Display_LCD(0,0," Mode Save Failure");
+            Display_LCD(0,0,"    Mode Save  ");
+            Display_LCD(0,1,"     Failure   ");
+            
             wait(1);
         }
-    }
+    
 }
 
 void CalculateTimeElapsed(float TimeElapsed, char *TimeStr)
@@ -679,184 +691,199 @@
 }
 
 
-              bool PasswordAcceptance()
-              {
-             Clear_LCD();
-             Display_LCD(0,0,"Enter Password ");   
-              char PasswordStr[5]={'\0'};
-              char temp='\0';
-              temp=keypad.waitForKey();
-              PasswordStr[0]=temp;
-              Display_LCD(0,1,PasswordStr);  
-              temp=keypad.waitForKey();
-              PasswordStr[1]=temp;
-               Display_LCD(0,1,PasswordStr);  
-              temp=keypad.waitForKey();
-              PasswordStr[2]=temp;
-               Display_LCD(0,1,PasswordStr);  
-              temp=keypad.waitForKey();
-              PasswordStr[3]=temp;
-               Display_LCD(0,1,PasswordStr);  
-              printf("Password Str %s\r\n",PasswordStr);
-               
-              if(PasswordStr[0]=='1' && PasswordStr[1] =='1' && PasswordStr[2]=='1' && PasswordStr[3]=='1')
-              {
-               Display_LCD(0,0,"Accepted "); 
-               printf("Accepted\r\n");   
-               return true;          
-              }     
-         return false;  
+bool PasswordAcceptance()
+{
+    Clear_LCD();
+    Display_LCD(0,0,"Enter Password ");
+    char PasswordStr[5]= {'\0'};
+    char temp='\0';
+    temp=keypad.waitForKey();
+    PasswordStr[0]=temp;
+    Display_LCD(0,1,PasswordStr);
+    temp=keypad.waitForKey();
+    PasswordStr[1]=temp;
+    Display_LCD(0,1,PasswordStr);
+    temp=keypad.waitForKey();
+    PasswordStr[2]=temp;
+    Display_LCD(0,1,PasswordStr);
+    temp=keypad.waitForKey();
+    PasswordStr[3]=temp;
+    Display_LCD(0,1,PasswordStr);
+    printf("Password Str %s\r\n",PasswordStr);
+
+    if(PasswordStr[0]=='1' && PasswordStr[1] =='1' && PasswordStr[2]=='1' && PasswordStr[3]=='1') {
+        Display_LCD(0,0,"Accepted ");
+        printf("Accepted\r\n");
+        return true;
+    }
+    return false;
+}
+
+
+int ModeSelectTochange()
+{
+    Clear_LCD();
+    Display_LCD(0,0,"Select Mode 1-6 ");
+    char str[2]= {'\0'};
+    char temp='\0';
+    temp=keypad.waitForKey();
+    if(temp>=0x31 && temp<=0x36) {
+        Display_LCD(0,1,"Mode Is: ");
+        str[0]=temp;
+        Display_LCD(9,1,str);
+        wait(1);
+        return (temp-0x30);
+    }
+    Display_LCD(0,0,"Invalid Mode");
+    return -1;
+
+}
+
+void fn(char rkey)
+{
+    char GreenTime[10]= {'\0'},YellowTime[10]= {'\0'},RedTime[10]= {'\0'};
+    bool Staus=false;
+    switch(rkey)
+
+    {
+        case '1':
+
+        {
+            Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                SaveTimes(1,GTIME,YTIME,RTIME);
+                Display_LCD(0,0,"Done Saving ");
+                Display_LCD(0,1,"Mode Saved");
+                wait(1);
+                Clear_LCD();
+            }
+            Staus=false;
         }
-        
-        
-       int ModeSelectTochange()
-       {
-              Clear_LCD();
-              Display_LCD(0,0,"Select Mode 1-6 ");   
-              char str[2]={'\0'};
-              char temp='\0';
-              temp=keypad.waitForKey();
-              if(temp>=0x31 && temp<=0x36)
-              {
-              Display_LCD(0,1,"Mode Is: "); 
-              str[0]=temp;
-              Display_LCD(9,1,str); 
-              wait(1);
-              return (temp-0x30); 
-              }
-               Display_LCD(0,0,"Invalid Mode"); 
-               return -1;
+        break;
+        case '2': {
+            Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                                           SaveTimes(2,GTIME,YTIME,RTIME);
+                Display_LCD(0,0,"Done Saving ");
+                Display_LCD(0,1,"Mode Saved");
+                wait(1);
+                Clear_LCD();
+            }
+            Staus=false;
+        }
+        break;
+        case '3': {
+            Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
                 
-        }
-        
-        
-        
-        
-        
-        
-   void fn(char rkey)
-   {
-         char GreenTime[10]={'\0'},YellowTime[10]={'\0'},RedTime[10]={'\0'};
-         bool Staus=false;
-         switch(rkey)
-         
-                        {
-                                                  
-                                    case '1':
+                printf("GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME %s   %s  %s  : %f  %f  %f \r\n ",GreenTime,YellowTime,RedTime,GTIME,YTIME,RTIME);
+                SaveTimes(3,GTIME,YTIME,RTIME);
                 
-                                      {
-                                        Staus=ReadAllTimesofEachMode(1,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-//                                           SaveTimes(1,GTIME,YTIME,RTIME);
-                                            Display_LCD(0,0,"Done Saving ");
-                                            Display_LCD(0,1,"Mode Saved");
-                                            wait(1);
-                                            Clear_LCD();
-                                        }
-                                        Staus=false;
-                                        }
-                                        break;
-                                    case '2':
-                                      {       
-                                        Staus=ReadAllTimesofEachMode(2,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-//                                           SaveTimes(2,GTIME,YTIME,RTIME);
-                                            Display_LCD(0,0,"Done Saving ");
-                                            Display_LCD(0,1,"Mode Saved");
-                                            wait(1);
-                                            Clear_LCD();
-                                        }
-                                        Staus=false;
-                                       }
-                                        break;
-                                    case '3':
-                                        {
-                                        Staus=ReadAllTimesofEachMode(3,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-//                                           SaveTimes(3,GTIME,YTIME,RTIME);
-                                            Display_LCD(0,0,"Done Saving ");
-                                            Display_LCD(0,1,"Mode Saved");
-                                            wait(1);
-                                            Clear_LCD();
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                                    case '4':
-                                        {
-                                        Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-//                                           SaveTimes(4,GTIME,YTIME,RTIME);
-                                            Display_LCD(0,0,"Done Saving ");
-                                            Display_LCD(0,1,"Mode Saved");
-                                            wait(1);
-                                            Clear_LCD();
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                                    case '5':
-                                        {
-                                        Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                Display_LCD(0,0,"Done Saving ");
+                Display_LCD(0,1,"Mode Saved");
+                wait(1);
+                Clear_LCD();
+            }
+            Staus=false;
+        }
+
+        break;
+        case '4': {
+            Staus=ReadAllTimesofEachMode(4,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                                          SaveTimes(4,GTIME,YTIME,RTIME);
+                Display_LCD(0,0,"Done Saving ");
+                Display_LCD(0,1,"Mode Saved");
+                wait(1);
+                Clear_LCD();
+            }
+            Staus=false;
+        }
+
+        break;
+        case '5': {
+            Staus=ReadAllTimesofEachMode(5,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
 //                                           SaveTimes(5,GTIME,YTIME,RTIME);
-                                            Display_LCD(0,0,"Done Saving ");
-                                            Display_LCD(0,1,"Mode Saved");
-                                            wait(1);
-                                            Clear_LCD();
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                
-                                    case '6':
-                                     {
-                                        Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime);
-                                        if(Staus==true)
-                                        {
-                                          
-                                           float GTIME=0,YTIME=0,RTIME=0;
-                                           ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
-//                                           SaveTimes(6,GTIME,YTIME,RTIME);
-                                            Display_LCD(0,0,"Done Saving ");
-                                            Display_LCD(0,1,"Mode Saved");
-                                            wait(1);
-                                            Clear_LCD();
-                                        }
-                                        Staus=false;
-                                        }
-                
-                                        break;
-                                    default:
-                                            Display_LCD(0,0,"No Mode saved");
-                                            Display_LCD(0,1,"Retns Prev Mode");
-                                            wait(1);
-                                            Clear_LCD();
-                                        printf("No Mode\r\n");
-                                        
-                            }
-                            
-                        }
\ No newline at end of file
+                Display_LCD(0,0,"Done Saving ");
+                Display_LCD(0,1,"Mode Saved");
+                wait(1);
+                Clear_LCD();
+            }
+            Staus=false;
+        }
+
+        break;
+
+        case '6': {
+            Staus=ReadAllTimesofEachMode(6,GreenTime,YellowTime,RedTime);
+            if(Staus==true) {
+                float GTIME=0,YTIME=0,RTIME=0;
+                ExtractTimesinSecs(GreenTime,YellowTime,RedTime,&GTIME,&YTIME,&RTIME);
+                                          SaveTimes(6,GTIME,YTIME,RTIME);
+                Display_LCD(0,0,"Done Saving ");
+                Display_LCD(0,1,"Mode Saved");
+                wait(1);
+                Clear_LCD();
+            }
+            Staus=false;
+        }
+        break;
+        default:
+            Display_LCD(0,0,"No Mode saved");
+            Display_LCD(0,1,"Retns Prev Mode");
+            wait(1);
+            Clear_LCD();
+            printf("No Mode\r\n");
+    }
+
+}
+
+
+
+
+   void Get_Time_Elapsed_after_Start(float timeInSec, char * str)
+   {
+     memset(str,'\0',6);
+     uint8_t  min=(int) timeInSec/60;
+     uint8_t  Secs=(int) timeInSec%60;
+     
+    if(min<10)
+    {
+     str[0]=0x30;
+     str[1]=min+0x30;    
+    }
+  else  if(min>=10)
+    {
+     str[0]=(min/10)+0x30;
+     str[1]=(min%10)+0x30;    
+    }
+    
+    str[2]=':';
+     if(Secs<10)
+    {
+     str[3]=0x30;
+     str[4]=Secs+0x30;    
+    }
+  else  if(Secs>=10)
+    {
+     str[3]=(Secs/10)+0x30;
+     str[4]=(Secs%10)+0x30;    
+    }
+    str[5]='\0';
+          
+ }
\ No newline at end of file