First servo test
This commit is contained in:
parent
1d381ebeac
commit
687112b41f
35
src/main.cpp
Normal file
35
src/main.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <ESP32Servo.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user