//Week 4 project electronic part
#include <Servo.h>
Servo main_servo;
int pos = 0;
int i = 0;
void setup() {
Serial1.begin(115200);
main_servo.attach(0);
}
void loop() {
for (pos = 0; pos <= 180; pos +=1){
if (pos % 15 == 0 && pos != 0) {
// Backward rotation of 5 degrees
for (i = 0; i <= 5; +=1){
main_servo.write(pos-i);
delay(50);
}
}
main_servo.write(pos);
delay(50);
}
for (pos = 180; pos >= 0; pos -=1){
if (pos % 15 == 0 && pos != 0) {
// Backward rotation of 5 degrees
for (i = 0; i <= 5; +=1){
main_servo.write(pos-i);
delay(50);
}
}
main_servo.write(pos);
delay(50);
}
}