mbed_binary_counter

Dependencies:   mbed

Revision:
0:858e3371c27e
Child:
1:4e311ab3af04
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 07 23:55:54 2014 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#define PRESSED 0
+#define UNPRESSED 1
+
+int getNext();
+
+DigitalIn pin8(p8); //button on pin8
+BusOut counter(LED4, LED3, LED2, LED1);
+ 
+//----------------------------------------------- 
+int main() {
+    
+    pin8.mode(PullUp); //set internal pullup
+    
+    bool previousState=pin8;
+    bool currentState;
+   
+    while(1) {
+        
+        currentState=pin8;
+        if(currentState==PRESSED && previousState==UNPRESSED){
+              counter=getNext();  
+            
+        }
+        previousState=currentState;
+        wait(0.1);
+        
+        
+        
+    }
+}
+
+
+//-----------------------------------------------
+int getNext(){
+    static int i=0;
+    if(i==15)i=0;
+    else i++;
+    
+    return i;
+    
+    }
\ No newline at end of file