Advertisement
Guest User

Working LED Code

a guest
Jul 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. int main(void)
  2. {
  3. /* USER CODE BEGIN 1 */
  4.  
  5. /* USER CODE END 1 */
  6.  
  7.  
  8. /* MCU Configuration--------------------------------------------------------*/
  9.  
  10. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  11. HAL_Init();
  12.  
  13. /* USER CODE BEGIN Init */
  14.  
  15. int buttonState = 0;
  16.  
  17. /* USER CODE END Init */
  18.  
  19. /* Configure the system clock */
  20. SystemClock_Config();
  21.  
  22. /* USER CODE BEGIN SysInit */
  23.  
  24. /* USER CODE END SysInit */
  25.  
  26. /* Initialize all configured peripherals */
  27. MX_GPIO_Init();
  28. /* USER CODE BEGIN 2 */
  29.  
  30. /* USER CODE END 2 */
  31.  
  32. /* Infinite loop */
  33. /* USER CODE BEGIN WHILE */
  34. while (1)
  35. {
  36. /*HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
  37. HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_14);
  38. HAL_Delay(500);*/
  39.  
  40. buttonState = HAL_GPIO_ReadPin(GPIOC,button_Pin);
  41.  
  42. if (buttonState == GPIO_PIN_SET){
  43. HAL_GPIO_WritePin(GPIOC,led_Pin,GPIO_PIN_SET);
  44. printf("button pressed\n");
  45. }
  46. else{
  47. HAL_GPIO_WritePin(GPIOC,led_Pin,GPIO_PIN_RESET);
  48. printf("button not pressed\n");
  49. }
  50. /* USER CODE END WHILE */
  51.  
  52. /* USER CODE BEGIN 3 */
  53. }
  54. /* USER CODE END 3 */
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement