Jurgis Jurksta / Mbed 2 deprecated TEST_with_daniel

Dependencies:   mbed Blinker TextLCD

Files at this revision

API Documentation at this revision

Comitter:
jurgis
Date:
Sat Jan 07 14:48:11 2017 +0000
Parent:
1:b95c3509df0f
Child:
3:0432064270e1
Commit message:
Added timer for ms reading

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Jan 07 12:51:53 2017 +0000
+++ b/main.cpp	Sat Jan 07 14:48:11 2017 +0000
@@ -1,38 +1,53 @@
 // Testing MBED with Daniel
 #include "mbed.h"
 
+double getWaitTime();
+
 DigitalOut led1(LED1);
 DigitalOut greenLed(D8);
+DigitalOut redLed(D10);
 DigitalIn button(D9);
+
 Serial pc(USBTX, USBRX);
 
 double ledWait = 0.2; // sec
+Timer timer;
+uint32_t prevMillis;
+uint32_t currentMillis;
 
-double getWaitTime()
-{
-    double waitTime = (button == 0) ? 0.2 : 1.0;
-    pc.printf("waitTime: %0.1f\r\n", waitTime);
-    return waitTime;
-}
 
 int main()
 {
+    timer.start();
+    currentMillis = prevMillis = timer.read_ms();
+    
     greenLed = 0;
+    redLed = 0;
     pc.baud(115200);
     pc.printf("Hello world\r\n");
     
     while(1)
     {
-        pc.printf("ON\r\n");
+        currentMillis = timer.read_ms();
+        pc.printf("%ld ms\r\n", currentMillis - prevMillis);
+        prevMillis = currentMillis;
+        
         led1 = 1; // LED is ON
         greenLed = 0;
+        redLed = 1;
         
         wait(getWaitTime());
         
-        pc.printf("OFF\r\n");
         led1 = 0; // LED is OFF
         greenLed = 1;
+        redLed = 0;
         
         wait(getWaitTime());
     }
 }
+
+
+double getWaitTime()
+{
+    return (button == 0) ? 0.2 : 1.0;
+}