From 687112b41f0b77cadec7c06f9d2f5d286ac7190a Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sun, 23 Jan 2022 17:57:48 +0100 Subject: [PATCH] First servo test --- src/main.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main.cpp diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b9f42da --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,35 @@ +#include +#include + +const int serialBaud = 115200; + +ESP32PWM pwm; +const int pwmTimer = 0; +Servo servo; +const int servoPin = 14; // Pin wired up to the servo data line +const int servoFrequency = 50; + +// Published values for Emax ES08MA II +const int minUs = 1500; +const int maxUs = 1900; + +void setup() { + Serial.begin(serialBaud); + + ESP32PWM::allocateTimer(pwmTimer); + + servo.setPeriodHertz(servoFrequency); + servo.attach(servoPin, minUs, maxUs); +} + +void loop() { + for (uint8_t i = 0; i < 10; i += 1) { + servo.write(i*10); + delay(1000); + } +} + +void end() { + servo.detach(); + pwm.detachPin(servoPin); +}