// https://www.youtube.com/watch?v=yVxjzu__ukI


// Servo rotation without delay.
#include <Servo.h>
Servo myservo;
int servoSpeed = 10;
#define ledPin 11
byte q[2] = {180, 90};
void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}
void loop() {
  //if (Serial.available())q[1] = Serial.parseInt();
  // if (q[0] % 2 == millis() / 100  % 2 && q[0] != q[1])Serial.println(q[1] / q[0] ? ++q[0] : --q[0]);
  // if (q[0] % 2 == millis() / 100  % 2 && q[0] != q[1])analogWrite(ledPin, q[1] / q[0] ? ++q[0] : --q[0]);
   if (q[0] % 2 == millis() / servoSpeed  % 2 && q[0] != q[1])myservo.write(q[1] / q[0] ? ++q[0] : --q[0]);
   if (q[0] == q[1])myservo.detach(); else myservo.attach(10);

  // if (++q[0] % 2 == 0)Serial.println(q[0]);
  // Serial.println(millis() / 3000  % 2);
  // Serial.println(0 ? ++q[0] : --q[0]);
}

/*

http://arduino.ru/forum/proekty/inkubator

https://www.youtube.com/watch?v=9D9381jkZrw

https://www.youtube.com/watch?v=whfoHSL2J8o

*/