2023-01-17 07:30 AM
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);
}
}
}
2023-01-18 02:23 AM
the AI apocalypse gets postponed again
2023-01-18 02:25 AM
he just posted it for you avobe