Andrew_S_C:
I know the controller board needs a 5v (@ Hi) input signal frequency of somewhere between 15 and 25Hz (I need to preset to each frequency value and, by trial and error, find the exact frequency that triggers the motor movement. The duty cycle will be in the range of 15% to 85% for the motor speed range.
…
A loop command may work but I've been concerned that just using the delay function would mess up the duty cycle percentage which is crucial to motor speed setting.
25Hz is 40 millis. If 40 divisions is a bit inaccurate, then use micros.
I suffix variables with the unit of measurement, so microseconds is us.
double frequency_Hz = 20.0; // adjust this to what your board needs
uint32_t wavelength_us = 1000000.0 / frequency_Hz;
double dutycycle_pct = 35;
uint32_t ontime_us = (double) wavelength_us * dutycycle_pct / 100.0;
uint32_t cycleStart_us;
void setup() {
cycleStart_us = micros();
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH);
}
void loop() {
uint32_t us = micros() - cycleStart_us;
while(us >= wavelength_us) {
// this method of adjusting the cyclestart gives more accurate cycles
cycleStart_us += wavelength_us;
us -= wavelength_us;
}
digitalWrite(pin, us < ontime_us ? HIGH : LOW);
}