cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt regarding multiple button press on STM32.

Killstreet30
Associate III

Hello,

I had a doubt regarding multiple button presses. Im trying to code a program so that every time I press a button the brightness of the LED decreases and once it reaches the minimum (5th button press), it increases back again after every button press. I have tried to code the same but am not getting the desired result. Please help. P.S I'm using timers and interrupts for the same.

Thank you.

Here is the code:

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_USART2_UART_Init();

 MX_TIM2_Init();

 HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);

 while (1)

 {

 }

}

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

int i;

if(GPIO_Pin==GPIO_PIN_13){

for(i=1;i<6;i++){

__HAL_TIM_SET_COMPARE(&htim2,TIM_CHANNEL_1, 1000/i);}

for(i=6;i>0;i=i-1){

__HAL_TIM_SET_COMPARE(&htim2,TIM_CHANNEL_1, 1000/i);

}

}

}

11 REPLIES 11

the AI apocalypse gets postponed again

we dont need to firmware by ourselves, lets talk

he just posted it for you avobe

we dont need to firmware by ourselves, lets talk