/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int ugol = 40;
int pos = 90-ugol; // variable to store the servo position
int k = 0; // определяет на каком ходу горит лазер (может быть 1 или 0)
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(7, OUTPUT);
}
void loop() {
for (pos = 90-(ugol); pos <= 90+(ugol); pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
digitalWrite(7, 1-k);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(40); // waits 15ms for the servo to reach the position
}
digitalWrite(7, k);
delay(1200);
for (pos = 90+(ugol); pos >= 90-(ugol); pos -= 1) { // goes from 180 degrees to 0 degrees
digitalWrite(7, 1-k);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(40); // waits 15ms for the servo to reach the position
}
digitalWrite(7, k);
delay(1200);
}