Amit_Dabhi
(Amit Dabhi)
January 24, 2022, 4:30pm
1
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
JohnnyK
(Jan Kamidra)
January 24, 2022, 4:46pm
2
Amit_Dabhi
(Amit Dabhi)
January 24, 2022, 6:08pm
3
Thank you, I’ve already looked at this. I’ve been looking at tickers in particular, and still can’t get get anything working.
JohnnyK
(Jan Kamidra)
January 24, 2022, 6:52pm
4
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
Amit_Dabhi
(Amit Dabhi)
January 25, 2022, 11:22am
5
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.
JohnnyK
(Jan Kamidra)
January 25, 2022, 12:33pm
6
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!
ThisThread::sleep_for(1s);
printf("loop\n");
}
}
BR, Jan