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.
9 years, 1 month ago.
Best way to change LED blink frequency based on application status
Hi, I'm wondering what the best way is to change the blink frequency depending on the status of some function. For example I'd like to introduce different LED blink frequency depending on thresholds I set for a sensor connected to an analog in PIN.
I tried to implement this with a global variable which is written from within the function that reads from analog in and evaluated by the ticker callback function to set a wait(). This would freeze my bluetooth stack
I found a working example that re-attaches the ticker from within the callback function but this uses a flag to control the ticker detach / attach. Not a big deal but I feel this is not the most elegant solution and might lead to bad maintainability and problems when others try to understand the code.
Is there a way how I could pass a float / integer when calling the callback function. How would you implement this?
void LedBlink(void) { led1 = !led1; if (ChangeStatusFlag) { // re-task ticker flash rate LedTicker.detach(); LedTicker.attach(&LedBlink,led_timer); ChangeStatusFlag = false; } }
Thanks, Jens
1 Answer
9 years, 1 month ago.
connect the led to a PWM port. Set duty cycle to say 0.5. Depending on the thresholds change the pulse width.