#include <Servo.h>
Servo myServo;
#define PIN_SERVO (8)
void SetStrokePerc(float strokePercentage)
{
if ( strokePercentage >= 1.0 && strokePercentage <= 99.0 )
{
int usec = 1000 + strokePercentage * ( 2000 - 1000 ) / 100.0 ;
myServo.writeMicroseconds( usec );
}
}
void SetStrokeMM(int strokeReq,int strokeMax)
{
SetStrokePerc( ((float)strokeReq) / strokeMax );
}
void setup()
{
myServo.attach(PIN_SERVO);
}
void loop()
{
int d = 10;
int delayMS = 1500;
int i = 0;
for ( i = 1; i < 99; i += d )
{
SetStrokePerc(i);
delay(delayMS);
}
for ( i = 99; i > 1; i -= d )
{
SetStrokePerc(i);
delay(delayMS);
}
}