Page 58 - MDP2022-2
P. 58
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM4_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
duty4 = 8;
if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_13) == GPIO_PIN_SET){
duty4++;
if(duty4 >= 10) duty4 = 10;
}
if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_11) == GPIO_PIN_SET){
duty4--;
if(duty4 <= 0) duty4 = 0;
}
if(HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_10) == GPIO_PIN_SET){ //Turn left when input to PD10
comes in
TIM4->CCR1 = duty4;
TIM3->CCR1 = 0;
}else if(HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_12) == GPIO_PIN_SET){ //Turn right when input to
PE12 comes in
TIM3->CCR1 = duty4;
TIM4->CCR1 = 0;
}else{
TIM3->CCR1 = duty4; //If there is no input, stop
TIM4->CCR1 = duty4;
}
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration