const byte RCInputPin = 2;
const byte StepPin = 3;
const byte DirectionPin = 4;
const unsigned MinStepRate = 70;
const unsigned MaxStepRate = 1600;
void setup()
{
pinMode(RCInputPin, INPUT);
pinMode(StepPin, OUTPUT);
pinMode(DirectionPin, OUTPUT);
digitalWrite(DirectionPin, LOW);
}
void loop()
{
unsigned long inputPulseWidth = pulseIn(RCInputPin, HIGH, 30000);
if (inputPulseWidth ! 0) // not a timeout
{
int stepRate = map(inputPulseWidth, 500, 2500, MinStepRate, MaxStepRate);
tone(StepPin, stepRate);
}
}
1 Like