#include <ESP32Servo.h>
// Create the servo object
Servo myServo;
// Variable to store the servo position
int pos = 0;
void setup() {
// Attaches the servo on pin 9 to the servo object
myServo.attach(18);
}
void loop() {
// TASK 1: Smooth movement from 0 to 180 degrees
// Student must write the for loop here:
for (int pos=0;pos=180;pos++)
{
myServo.write(pos);
delay(1000);
}
delay(1000); // Pause at 180 degrees
// TASK 2: Smooth movement from 180 back to 45 degrees
// Student must write the for loop here:
for (int pos=180;pos=45;pos--)
{
myServo.write(pos);
delay(1000);
}
delay(1000); // Pause at 45 degrees
}