cancel
Showing results for 
Search instead for 
Did you mean: 

I would like to ask a question about button control! Hope to receive a reply!

Bwang.3
Associate III

I looked at the routine of SPC582B60E1! In the routine, pressing a button can use the callback function that interrupts the button to light up the LED light, but I have a question: how can I turn off the already lit LED light when I release the button? Can you give me some ideas or routines? I want to learn them! This is very important to me, thank you all big shots!

6 REPLIES 6
Max VIZZINI
ST Employee

Hi,

You need to set 2 external interrupts: 1 on raising edge and 1 on falling edge.

Best Regards,

AutoDevKit Team

Hello! What I want to ask is can a button set both rising and falling edge interrupts simultaneously?

Hello! The function I want to achieve is that when the same button is pressed, the LED light will light up, and when the button is released, the LED light will go out! You mentioned using two external interrupts, one generating an interrupt on the rising edge and the other generating an interrupt on the falling edge! But what I don't know is how can two types of interrupts be set for the same button (i.e. the same pin)? Both the rising and falling edge interruptions can occur simultaneously! If so, can you tell me how to set it up?

Hi,

The button generates an interrupt to the MCU. 

You can set on both raising and falling edge the interrupt.

Best Regards,

AutoDevKit Team

Hello! I have found the interrupt option to set both the rising and falling edges simultaneously! As shown in the following picture! But how can I write the callback function in the program to turn on the LED light on the rising edge and turn off the LED light on the falling edge? Can we add another interrupt setting with the same interrupt number and then write a callback function with a falling edge to execute the LED light off! Hope to receive your guidance! Thank you!

QQ图片20240530223835.pngQQ图片20240530224603.png

Hello! I have defined two interrupts in the external interrupt EIRQ17, namely the rising edge interrupt and the falling edge interrupt! As shown in the following picture! Is this definition acceptable? Also, can the name of this Callback only be written as cb_eirq17? If that's the case, then if I define the callback functions for the rising and falling edges as having the same name, will the program execute incorrectly due to the same callback function name during execution?

QQ图片20240530230956.pngQQ图片20240530231048.pngQQ图片20240530231145.png