#include <Servo.h>
Servo ESC;
const byte
IN1 = 4,
IN2 = 5,
IN3 = 6,
IN4 = 7,
MotorPin = 8
;
void setup ()
{
pinMode ( IN1, INPUT_PULLUP );
pinMode ( IN2, INPUT_PULLUP );
pinMode ( IN3, INPUT_PULLUP );
pinMode ( IN4, INPUT_PULLUP );
ESC.attach ( MotorPin, 1000, 2000 );
}
void loop ()
{
if ( digitalRead ( IN1 ) == LOW )
{
ESC.write ( 45 ); // 1/4 speed
}
else if ( digitalRead ( IN2 ) == LOW )
{
ESC.write ( 90 ); // 1/2 speed
}
else if ( digitalRead ( IN3 ) == LOW )
{
ESC.write ( 135 ); // 3/4 speed
}
else if ( digitalRead ( IN4 ) == LOW )
{
ESC.write ( 180 ); // full speed
}
else
{
ESC.write ( 0 ); // stand still
}
}