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.
7 years, 6 months ago.
LED blink to let us know the CPU is alive
How could I incorporate a program into 'main' to just blink an led to let us know the CPU is alive ? Would I have to use a nested while loop? Any suggestions?
1 Answer
7 years, 6 months ago.
Hello Paul,
What you want to implement is a heartbeat. So inside your main program, you can toggle an LED every time your program goes through one loop. For example:
Looping Heartbeat
#include "mbed.h"
DigitalOut heartbeat (LED1);
int main() {
while(1)
//your main program implementation
heartbeat =!heartbeat;
}
}
Another way that you can do this is to do an interrupt heartbeat, which will toggle an LED at a certain frequency. Example:
Looping Heartbeat
#include "mbed.h"
Ticker heart;
DigitalOut beat (LED1);
void pumping(){
beat =!beat;
}
int main() {
flipper.attach(&pumping, 1.0); // the address of the function to be attached (heart) and the interval (1 seconds or 1 Hertz)
//your main program implementation
}
Please let me know if you have any questions!
- Peter, team Mbed
If this solved your question, please make sure to click the "Thanks" link below!