17 lines
350 B
C
17 lines
350 B
C
#include "servo.h"
|
|
#include "tim.h"
|
|
|
|
void SERVO_Init()
|
|
{
|
|
__HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_4, 150);
|
|
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);
|
|
}
|