Created
March 17, 2021 11:25
-
-
Save elktros/46582bb9db3acd24a5983bd8ffad1a53 to your computer and use it in GitHub Desktop.
Sweep program for ESP32 Servo Control.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ESP32 Servo Sweep */ | |
const int servoPin = 16; /* GPIO16 */ | |
int dutyCycle = 0; | |
/* Setting PWM properties */ | |
const int PWMFreq = 50; | |
const int PWMChannel = 0; | |
const int PWMResolution = 8; | |
//const int MAX_DUTY_CYCLE = (int)(pow(2, PWMResolution) - 1); | |
void setup() | |
{ | |
Serial.begin(115200); | |
ledcSetup(PWMChannel, PWMFreq, PWMResolution); | |
/* Attach the LED PWM Channel to the GPIO Pin */ | |
ledcAttachPin(servoPin, PWMChannel); | |
ledcWrite(PWMChannel, dutyCycle); | |
} | |
void loop() | |
{ | |
for(dutyCycle = 5; dutyCycle <= 32; dutyCycle++) | |
{ | |
ledcWrite(PWMChannel, dutyCycle); | |
delay(70); | |
} | |
for(dutyCycle = 32; dutyCycle >= 5; dutyCycle--) | |
{ | |
ledcWrite(PWMChannel, dutyCycle); | |
delay(70); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment