use the PortInOut class to make a key_controlled counter

Dependencies:   mbed

Fork of PortInOut_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
shiyilei
Date:
Fri Oct 17 01:29:32 2014 +0000
Parent:
1:1a2e0383909d
Commit message:
use the PortInOut Class to make a key_controlled counnter

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1a2e0383909d -r 7e1bc5947174 main.cpp
--- a/main.cpp	Sun Sep 21 17:27:59 2014 +0000
+++ b/main.cpp	Fri Oct 17 01:29:32 2014 +0000
@@ -1,19 +1,30 @@
-// Toggle all four LEDs
- 
-#include "mbed.h"
- 
-// LED1 = P1.18  LED2 = P1.20  LED3 = P1.21  LED4 = P1.23
-#define LED_MASK 0x00B40000
- 
-PortInOut ledport(Port1, LED_MASK);
- 
+/*************************************************
+*file:time counter
+*creator:JacobShi
+*Time:2014/10/16
+* Description: uses the portInOut to make a keycrolled couter
+**************************************************/
+#include "mbed.h" 
+char data[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
+PortInOut lednumber(Port0,0x000000ff);
+PortInOut keycontrol(Port1,0x00000001);
+int i=0;
 int main() {
-    int v = ledport;
-    ledport.output();
-    while(1) {
-        ledport = LED_MASK;
-        wait(0.5);
-        ledport = 0;
-        wait(1);
+    lednumber.output();
+    keycontrol.input();
+    while(1) 
+    {
+        if(!keycontrol)
+        {
+            wait_ms(10);
+            if(!keycontrol)
+            {
+                while(!keycontrol);
+                lednumber=data[i];
+                (i++)%10;     
+            }   
+
+        }       
+
     }
 }
\ No newline at end of file