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

main.cpp

Committer:
shiyilei
Date:
2014-10-27
Revision:
5:48debf3fb005
Parent:
1:c27c61c0a1e0

File content as of revision 5:48debf3fb005:

/*********************************************
*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;

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);
     }
}

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;
}