#include "servo.h" #include "tim.h" void SERVO_Init() { HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4); } void SERVO_Rotate(uint8_t degree) { if (degree > 180) degree = 180; uint16_t compare = 200.0 / 180 * degree + 50; __HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_4, compare); }