ultrasonic distance sensor - time headerfile

Dependencies:   N5110 PowerControl SRF02 beep mbed

Fork of Ultrasonicdistancesensor by I Adam

Revision:
1:920749af1300
Parent:
0:7a82ad48df33
Child:
2:184524f95eb1
--- a/ultrasonic.cpp	Tue May 05 00:39:32 2015 +0000
+++ b/ultrasonic.cpp	Tue May 05 03:08:14 2015 +0000
@@ -25,6 +25,8 @@
 InterruptIn button2 (p29);
 InterruptIn button3 (p30);
 
+ 
+ 
 
 //===============================
 int button1Flag = 0;
@@ -65,6 +67,22 @@
 int clockFlag = 0;
 //------------------------------
 
+Ticker distTimer;
+int dstFlg = 0;
+void distChk()
+{
+    dstFlg = 1;      
+}    
+
+
+Ticker clkTimer;
+int clkFlg = 0;
+void clkChk()
+{
+    clkFlg = 1;      
+}    
+
+
 
 int main()
 {
@@ -73,9 +91,10 @@
    
    // button2.rise(&button2Pressed);
    
-    beeper(1000, 0.5); 
+    //beeper(1000, 0.5); 
  
     serial.attach(&serialISR); // attach serial ISR
+    timer2.attach(&timer2Expired,1.0);
     
     set_time(1424535031); // initialise time to 1st January 1970
     
@@ -87,7 +106,8 @@
 //-----------------------------------------------------
    
 //-----------------------------------------------------
-     
+    distTimer.attach(&distChk, 1.0); //call ISR every 5 sec
+    clkTimer.attach(&clkChk, 1.0); //call ISR every 5 sec
     while(1) 
     { 
         if (msgFlag)
@@ -105,38 +125,50 @@
         if (menuLevelFlag)
         {
             button1Flag =0;
-            menuLevel(potIn);
+            menuLevel(potIn);   
         }
         
-        if (distFlag)
+         if (distFlag)
         {
             menuLevelFlag = 0;
-            distMeasure();
-            if(button1)
+            if (dstFlg)
             {
-                distFlag = 0;         
-            } 
-                   
+                dstFlg = 0;
+                distMeasure();
+                if(button1)
+                {
+                    distFlag = 0;         
+                } 
+             }      
         } 
         
        if (brightFlag)
         {       
             menuLevelFlag = 0;
-            adjustBrightness(potIn); 
-            if (button1)
-            {
-                brightFlag = 0;  
-            }    
+            
+                
+                adjustBrightness(potIn); 
+                if (button1)
+                {
+                    brightFlag = 0;  
+                }
+                
         }
         if (clockFlag)
         {
             menuLevelFlag = 0;
-            displayClock();
-            if (button1)
+            if (clkFlg)
             {
-                clockFlag = 0;   
-            }       
-        }        
+                clkFlg = 0;
+                displayClock();
+                if (button1)
+                {
+                    clockFlag = 0;   
+                } 
+                }
+            }          
+               
+        
      }   
 }
 
@@ -218,34 +250,39 @@
     {
         if ((x >= 0) && (x < 0.2))
         {   
+               
             lcd.setBrightness(0);
             lcd.printString("Light 0%",13,1);    
         }
         
         if ((x >= 0.2) && (x < 0.4))
         {
+               
             lcd.setBrightness(0.25);
             lcd.printString("Light 25%",13,1);
         }
         
         if ((x >= 0.4) && (x < 0.6))
         {
+               
             lcd.setBrightness(0.5);
             lcd.printString("Light 50%",13,1);  
         }
         
         if ((x >= 0.6) && (x < 0.8))
         {
+               
             lcd.setBrightness(0.75);
             lcd.printString("Light 75%",13,1); 
                
         }
         if (x >= 0.8) 
         {
+               
             lcd.setBrightness(1);
             lcd.printString("Light 100%",13,1);   
         }
-        lcd.clear();    
+          lcd.clear();  
     }   
     
 void menu()
@@ -427,6 +464,7 @@
             brightFlag = 0;     
         }          
     }
+       
                                    
 }    
 void clockA()
@@ -451,7 +489,7 @@
     }
     
    // serial.printf("Distance = %d cm\n",distance);
-    serial.printf("\n\n\r %s, %0.2f C\n",buffer, length);
+    serial.printf("\n\n\r %s, %0.2f \n",buffer, length);
     
 }  
   
@@ -472,8 +510,8 @@
 } 
 void displayClock()
 {
-    timer2.attach(&timer2Expired,1.0);
-    serial.attach(&serialISR); // attach serial ISR
+    //timer2.attach(&timer2Expired,1.0);
+    //serial.attach(&serialISR); // attach serial ISR
     lcd.clear();
     
     lcd.printString("-SYS CLOCK-",9,0);