Hey everybody, I'm trying to use the Arduino to receive Serial commands and then send pulses out, but I cannot use the built in analogWrite because the device I'm communicating with (Victor 883) requires different high and low pulse periods than the default analogWrite. I have written code that does this successfully:
void drive(int dir, int percent){
int pulse;
if(dir == 0 || percent == 0){
pulse = 1500;
}else if(dir == 1){ // forward
pulse = map(percent, 0, 100, 1550, 2010);
}else{ // reverse
pulse = map(percent, 0, 100, 1490, 1060);
}
digitalWrite(motorPin, HIGH);
delayMicroseconds(pulse);
digitalWrite(motorPin, LOW);
delay(37);
delayMicroseconds(3000 - pulse);
}
But now I need to put this in another program that is constantly polling serial devices and communicating to a computer and these delays are messing up the timing in this code. If I use analogWrite, I could maintain the pulses while these serial events were happening, but I don't know how to do that with my own custom pulse function. Can anyone point me in the right direction?