esp32 devkitc-1 驱动sg90舵机的问题
Posted: Thu Jul 14, 2022 6:25 am
开发环境:arduino
想用自带的LEDPWD来驱动sg90 发现没有反应
想用自带的LEDPWD来驱动sg90 发现没有反应
- int freq = 50;
- int channel = 7;
- int resolution = 8;
- const int led = 16;
- int servo_max=180,servo_min=90;
- int calculatePWM(int degree)
- {
- const float deadZone = 6.4;
- const float max = 32;
- if (degree < 0)
- degree = 0;
- if (degree > 180)
- degree = 180;
- return (int)(((max - deadZone) / 180) * degree + deadZone);
- }
- void setup()
- {
- Serial.begin(9600);
- ledcSetup(channel, freq, resolution); // 设置通道
- ledcAttachPin(led, channel); // 将通道与对应的引脚连接
- }
- void loop()
- {
- ledcWrite(channel, calculatePWM(90));
- delay(1000);
- ledcWrite(channel, calculatePWM(180));
- delay(1000);
- }