Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hi:
I would like to call the stop() member function from a RtosTimer object, however, this is a bit difficult:
#include "mbed.h" #include "rtos.h" DigitalOut Led1(LED1); DigitalOut Led2(LED2); int State; void Blink(void const *n) { if (State == 1) { Led1 = 1; Led2 = 0; State = 2; } else if (State == 2) { LedTimer.stop(); Led1 = 0; Led2 = 1; LedTimer.start(10000); // longer timer alarm State = 1; } } int main(void) { State = 1; RtosTimer LedTimer(&Blink, osTimerPeriodic, NULL); LedTimer.start(500); // short timer alarm Thread::wait(osWaitForever); }As RtosTimer is defined within main(), Blink could not see it. If I define LedTimer() outside but before Blink, the code could compile but the code will crash (4 blinking blue LEDs).
Any suggestion?