Oscar Schofield / Mbed 2 deprecated Elec350_OBS

Dependencies:   mbed

Revision:
3:8dca756d9804
Parent:
2:e3cd1e0c3b78
Child:
4:5d531bd3c4ea
--- a/button.cpp	Thu Oct 15 11:38:52 2015 +0000
+++ b/button.cpp	Tue Oct 20 09:49:08 2015 +0000
@@ -1,5 +1,5 @@
 #include "button.h" //header file included
-
+#include "mbed.h"
 
 Button::Button(string s){
     if (s == "user"){
@@ -9,4 +9,19 @@
 
 bool Button::ifPressed(){
     return *pin;
-}
\ No newline at end of file
+}
+
+float Button::Duration(){
+    Timer timer;
+    float duration = 0;
+    timer.reset();
+    while (duration==0){
+        while (*pin==1){
+            timer.start();
+        }
+        duration= timer.read_ms();
+        timer.stop();
+    }
+    return duration;
+}
+    
\ No newline at end of file