5 years, 10 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

5 years, 10 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!

Accepted Answer

Thanks Peter, that's exactly what I was looking for.

posted by Paul Smith 20 Jun 2018