User button example (L152)

Name of the project

l152_user_button

Description

Based on an ST.Microelectronics example, the application change the blinking frequency of the LED when pressing the user button (blue) on the Nucleo-L152RE board.

Code snippet (initial code, project structure and VSCode files generated by VPC):

uint8_t speed = 0;

void EXTI15_10_IRQHandler(void){
  // Here would be the B1 pin interrupt handler (do where it says "do something..."):
  if ((EXTI_GetITStatus(EXTI_Line13)) != RESET){
    // do something...
    if(speed == 2) speed = 0;
    else speed++;
    // don't touch:
    EXTI_ClearITPendingBit(EXTI_Line13);
  }
}
 
  
int main(void){
  /* local variables */
  
  /* mandatory system initializations */
  vpc_system_init();
  //vpc_rtc_init(); /* enable if required */  
  vpc_gpio_init();
  //vpc_usart2_uart_init(); /* enable if required */ 
  /* third-party initializations */
  
  /* do your own initializations below */
  
  while(1){
    /* your forever repeating code */
    GPIO_ToggleBits(LD2_GPIO_Port, LD2_Pin);
    if (speed == 0) my_delay_ms(50);
    if (speed == 1) my_delay_ms(250);
    if (speed == 2) my_delay_ms(500);
  }
  return 0;
}
 

Project published in repository.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.