Flashing Lights Mbed

Hi, I’m using a K64F board I have have an input (PTB9) and want it to flash two LED (PTA1 and PTA2) outputs I have connected to it every 0.5 seconds.

So when button is pressed LED flash and when button is pressed again, they turn off. Any help?
Thank you


just start with example of InterruptIn - API references and tutorials | Mbed OS 6 Documentation

BR, Jan

Thank you, I’ve already looked at this. I’ve been looking at tickers in particular, and still can’t get get anything working.

Can you be more specific? I probably do not understand what do you want.
You descripted simple example of a user button and a led, and you talking about a ticker now.

Ideally show your code and mark what is not working.

BR, Jan

My bad sorry, I don’t know how to write a code for what I need to do, I’ve looked at interrupts, but still don’t know how to write it.

But the Description is quite simple, push a button once, it makes LEDs flash, and push it again it turns it off.

Down on page (what I provided via the link above) is an example of that what you exactly want.
So code based on the example can looks like below

#include "mbed.h"

InterruptIn button(PTB9);
DigitalOut led1(PTA1);
DigitalOut led2(PTA2);

void flip()
    led1 = !led1;
    led2 = !led2;

int main()
    button.rise(&flip);  // attach the address of the flip function to the rising edge
    while (1) {          // wait around, interrupts will interrupt this!

BR, Jan