If the key is low the led is ON else turn off the led

Dependencies:   mbed-rtos mbed

Fork of rtos_timer by mbed official

Files at this revision

API Documentation at this revision

Comitter:
shiyilei
Date:
Mon Oct 27 04:44:27 2014 +0000
Parent:
4:9dd7d49be2c3
Commit message:
If the key is low the led is ON else turn off the led

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 9dd7d49be2c3 -r 48debf3fb005 main.cpp
--- a/main.cpp	Tue Jun 04 16:05:58 2013 +0100
+++ b/main.cpp	Mon Oct 27 04:44:27 2014 +0000
@@ -1,24 +1,51 @@
+/*********************************************
+*file name :key_scan in the rtos
+*Creator:JacobShi
+*Time:2014/10/27
+*Description: use the timer in the RTOS to
+*scan the key .If the key is low the led is
+*ON else turn off the led
+ ******************************************/
 #include "mbed.h"
 #include "rtos.h"
+DigitalOut myled(LED1);
+DigitalIn  mykey(p18);
+int key_state=0;
 
-DigitalOut LEDs[4] = {
-    DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
-};
-
-void blink(void const *n) {
-    LEDs[(int)n] = !LEDs[(int)n];
+void led1_task ( void const *args )
+{
+    char *data=(char *)args;
+    printf("%s\n",data);
+    while(1)
+     {   
+            if(key_state==1)
+                myled=1;
+            else
+                myled=0;
+            Thread::wait(10);
+     }
 }
 
-int main(void) {
-    RtosTimer led_1_timer(blink, osTimerPeriodic, (void *)0);
-    RtosTimer led_2_timer(blink, osTimerPeriodic, (void *)1);
-    RtosTimer led_3_timer(blink, osTimerPeriodic, (void *)2);
-    RtosTimer led_4_timer(blink, osTimerPeriodic, (void *)3);
-    
-    led_1_timer.start(2000);
-    led_2_timer.start(1000);
-    led_3_timer.start(500);
-    led_4_timer.start(250);
-    
-    Thread::wait(osWaitForever);
+void key_scan(void const *args)
+{
+  if(!mykey)
+    key_state=1;
+  else
+    key_state=0;
 }
+
+int main(void)
+{
+  
+ myled=0;
+    Thread thread1(led1_task,(void *)"test key process");
+  RtosTimer timer1(key_scan,osTimerPeriodic,(void *)0);
+ timer1.start(10);
+
+  while(1)
+  {
+
+
+  }
+  return 0;
+}
\ No newline at end of file
diff -r 9dd7d49be2c3 -r 48debf3fb005 mbed-rtos.lib
--- a/mbed-rtos.lib	Tue Jun 04 16:05:58 2013 +0100
+++ b/mbed-rtos.lib	Mon Oct 27 04:44:27 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed-rtos/#e2da1b20a6d5
diff -r 9dd7d49be2c3 -r 48debf3fb005 mbed.bld
--- a/mbed.bld	Tue Jun 04 16:05:58 2013 +0100
+++ b/mbed.bld	Mon Oct 27 04:44:27 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file