#include <Servo.h>
Servo myservo_H; // create servo object to control a servo
// twelve servo objects can be created on most boards
Servo myservo_V;
int ugol = 55;
int startV = 20;
int pos = 90-ugol; // variable to store the servo position
int k = 0; // определяет на каком ходу горит лазер (может быть 1 или 0)
void setup() {
myservo_H.attach(9); // attaches the servo H on pin 9 to the servo object
myservo_V.attach(8);
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_H.write(pos); // tell servo to go to position in variable 'pos'
myservo_V.write(startV-pos/15);
delay(12); // waits 15ms for the servo to reach the position
}
digitalWrite(7, k);
delay(2000);
for (pos = 90+(ugol); pos >= 90-(ugol); pos -= 1) { // goes from 180 degrees to 0 degrees
digitalWrite(7, 1-k);
myservo_H.write(pos); // tell servo to go to position in variable 'pos'
myservo_V.write(startV-(180-pos)/15);
delay(12); // waits 15ms for the servo to reach the position
}
digitalWrite(7, k);
delay(2000);
}