#include "tservo2.h"

tservo servo1(9), servo2(10,true), led0(8);                 // create servo object to control a servo 
                                       
unsigned pos = 0;                           // variable to store the servo position 
unsigned int add = 5;
unsigned int add2 = 50;
unsigned int add3 = 10; 

void setup() 
{ 
/*  
  myservo2.attach(7); 
  servo1.attach(5); 
  servo2.attach(6);
                 // attaches the servo on PB1 to the servo object 
*/
 // initialize the serial communication:
  Serial.begin(9600);
  servo1 = 0;
  servo2 = 2600;
  led0 = 500; 
  delay(100);
} 

void loop() 
{ 
  //Serial.println((unsigned)servo1, (unsigned) servo2);
   servo1=(unsigned) servo1+add;
   if((unsigned)servo1 < 0 || (unsigned)servo1 > 180) {
     add = -add;
   }
  servo2=(unsigned) servo2+add2;
   if((unsigned)servo2 < 450 || (unsigned)servo2 > 2600) {
     add2 = -add2;  
  
   }
   led0=(unsigned) led0+add3;
   if((unsigned)led0 < 0 || (unsigned)led0 > 180) {
     add3 = -add3;  
  
   }
   
   delay(10);
}
/**
 * Make sure that given value is not over min_value/max_value range.
 *
 * @param float value     : The value to convert
 * @param float min_value : The min value
 * @param float max_value : The max value
 *
 * @return float
 */
float minMax(float value, float min_value, float max_value) {
    if (value > max_value) {
        value = max_value;
    } else if (value < min_value) {
        value = min_value;
    }

    return value;
}