#include "tservo2.h"
tservo servo1(9,true), servo2(10,true), led0(8,true); // create servo object to control a servo
unsigned pos = 0; // variable to store the servo position
unsigned int add = 10;
unsigned int add2 = 10;
unsigned int add3 = 15;
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 = 1000;
servo2 = 1000;
led0 = 1000;
delay(100);
}
void loop()
{
//Serial.println((unsigned)servo1, (unsigned) servo2);
servo1=(unsigned) servo1+add;
if((unsigned)servo1 <= 450 || (unsigned)servo1 >= 2500) {
add = -add;
}
servo2=(unsigned) servo2+add2;
if((unsigned)servo2 <= 450 || (unsigned)servo2 >= 2500) {
add2 = -add2;
}
led0=(unsigned) led0+add3;
if((unsigned)led0 <= 450 || (unsigned)led0 >= 2500) {
add3 = -add3;
}
delay(5);
}
/**
* 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;
}