Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Create a program to sweep the servo back and forth between 0o and 180o gradually such that it takes a total of 18 seconds to complete a back and forth sweep

Hint :

  • Increment and decrement by 1o, with a 50 milliseconds delay at each step

C++

Blocks

Code Block
languagecpp
#include <Servo.h>
  
Servo myservo;

...


int pos = 0;   

...

// variable to store the servo position
 
void setup()

...


{

...


  myservo.attach(7); 

...

}
 
void loop()

...

{
  

...

for(pos = 0; pos <= 180; pos++)
  {                               
    

...

myservo.write(pos);

...

           
    delay(50);

...

                    
  }
  

...

for(pos = 180; pos >= 0; pos--)  
  

...

{                               
    

...

myservo.write(pos);           
    

...

delay(50);                    
  

...

}

...

}

image2020-1-20_18-8-41.pngImage Added