In the past I've done a bit with arduino PWM DC motor control with various sensors, but have not played around with writing a control program without sensors. So basically I want a motor to go from "stopped" to full "forward"or "reverse" in a specific amount of time without using sensors to tell it when to start- stop etc. In the code below I'm using the PWM range, but it seems kind finicky in terms of how long the motors go either way. Is there a better strategy/easy solution anyone knows right off, or do you have to tediously adjust value ranges for motion? I've played about with the "millis" function but no joy. Don't know if anyone would be so kind as to know of a better function or way to apply a specific time range to an analogWrite. Apologies for being a syntax troglodyte. Any help greatly appreciated.
Here's the mishmash I'm rocking right now
int leftmotor = 10; //left motor
int rightmotor = 11; //right motor
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
reverse();
delay (1500);
forward();
delay (1500);
}
// BEHAVIOR FUNCTIONS
void reverse(){
for (int b = 190; b >= 127; b--){
analogWrite(leftmotor, b);
analogWrite(rightmotor, b);
Serial.println("REVERSE");
}
}
void forward(){
for (int i = 190; i <= 252; i++){
analogWrite(leftmotor, i);
analogWrite(rightmotor, i);
Serial.println("FORWARD");
}
}
void stop_forever(){
for (int i = 140; i < 150; i++){
analogWrite(leftmotor, 0);
analogWrite(rightmotor, 0);
Serial.println("STOPFOREVER");
delay(100);
}
}