Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Sweep
- by BARRAGAN <http://barraganstudio.com>
- This example code is in the public domain.
- modified 28 May 2015
- by Michael C. Miller
- modified 8 Nov 2013
- by Scott Fitzgerald
- // use Vin and GND
- use pins D7, GND and 5V
- http://arduino.cc/en/Tutorial/Sweep
- */
- #include <Servo.h>
- Servo myservo; // create servo object to control a servo
- void setup() {
- Serial.begin(115200);
- // d7 on the wemos D1
- // attaches the servo on GIO2 to the servo object
- myservo.attach(13);
- }
- void loop() {
- int pos;
- int startPosition = -10;
- int endPosition = 80;
- int millisecondStep = 10;
- for (pos = startPosition; pos <= endPosition; pos += 1) { // goes from 0 degrees to 180 degrees
- // in steps of 1 degree
- Serial.print(pos);
- Serial.print("\n");
- myservo.write(pos);
- delay(millisecondStep);
- }
- for (pos = endPosition; pos >= -startPosition; pos -= 1) {
- myservo.write(pos);
- delay(millisecondStep);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement