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

Committer:
shiyilei
Date:
Mon Oct 27 04:44:27 2014 +0000
Revision:
5:48debf3fb005
Parent:
1:c27c61c0a1e0
If the key is low the led is  ON else turn off the led

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shiyilei 5:48debf3fb005 1 /*********************************************
shiyilei 5:48debf3fb005 2 *file name :key_scan in the rtos
shiyilei 5:48debf3fb005 3 *Creator:JacobShi
shiyilei 5:48debf3fb005 4 *Time:2014/10/27
shiyilei 5:48debf3fb005 5 *Description: use the timer in the RTOS to
shiyilei 5:48debf3fb005 6 *scan the key .If the key is low the led is
shiyilei 5:48debf3fb005 7 *ON else turn off the led
shiyilei 5:48debf3fb005 8 ******************************************/
emilmont 1:c27c61c0a1e0 9 #include "mbed.h"
emilmont 1:c27c61c0a1e0 10 #include "rtos.h"
shiyilei 5:48debf3fb005 11 DigitalOut myled(LED1);
shiyilei 5:48debf3fb005 12 DigitalIn mykey(p18);
shiyilei 5:48debf3fb005 13 int key_state=0;
emilmont 1:c27c61c0a1e0 14
shiyilei 5:48debf3fb005 15 void led1_task ( void const *args )
shiyilei 5:48debf3fb005 16 {
shiyilei 5:48debf3fb005 17 char *data=(char *)args;
shiyilei 5:48debf3fb005 18 printf("%s\n",data);
shiyilei 5:48debf3fb005 19 while(1)
shiyilei 5:48debf3fb005 20 {
shiyilei 5:48debf3fb005 21 if(key_state==1)
shiyilei 5:48debf3fb005 22 myled=1;
shiyilei 5:48debf3fb005 23 else
shiyilei 5:48debf3fb005 24 myled=0;
shiyilei 5:48debf3fb005 25 Thread::wait(10);
shiyilei 5:48debf3fb005 26 }
emilmont 1:c27c61c0a1e0 27 }
emilmont 1:c27c61c0a1e0 28
shiyilei 5:48debf3fb005 29 void key_scan(void const *args)
shiyilei 5:48debf3fb005 30 {
shiyilei 5:48debf3fb005 31 if(!mykey)
shiyilei 5:48debf3fb005 32 key_state=1;
shiyilei 5:48debf3fb005 33 else
shiyilei 5:48debf3fb005 34 key_state=0;
emilmont 1:c27c61c0a1e0 35 }
shiyilei 5:48debf3fb005 36
shiyilei 5:48debf3fb005 37 int main(void)
shiyilei 5:48debf3fb005 38 {
shiyilei 5:48debf3fb005 39
shiyilei 5:48debf3fb005 40 myled=0;
shiyilei 5:48debf3fb005 41 Thread thread1(led1_task,(void *)"test key process");
shiyilei 5:48debf3fb005 42 RtosTimer timer1(key_scan,osTimerPeriodic,(void *)0);
shiyilei 5:48debf3fb005 43 timer1.start(10);
shiyilei 5:48debf3fb005 44
shiyilei 5:48debf3fb005 45 while(1)
shiyilei 5:48debf3fb005 46 {
shiyilei 5:48debf3fb005 47
shiyilei 5:48debf3fb005 48
shiyilei 5:48debf3fb005 49 }
shiyilei 5:48debf3fb005 50 return 0;
shiyilei 5:48debf3fb005 51 }