OK, I am looking at using a function to spool up and spool down the motors and handle the duration timer. Here is what I have that does not work. Please Help!//////////////////////////////
#define STIRRING1_TIME 20 // 1200
#define Srelay 51
int stir_speed = 180;
int time = 0;
int pump_pwm_del = 1;
int second = 0;
void setup() {
Serial.begin(57600);
Serial.println("setup");
digitalWrite(23,HIGH);
/////////////////////////////
pinMode(Srelay, OUTPUT); // Provides/Removes Power to motor controllers
pinMode(44, OUTPUT); //Shared PWM Signal to all 4 motor controllers
pinMode(23, OUTPUT); //Stir motor
digitalWrite(Srelay,LOW);//Turn off power to motor controllers
}
void loop() {
digitalWrite(Srelay,HIGH);//Turn off power to motor controllers
Serial.println("23");
stir(10);
}
/////////////////////////////////////////////////////////
//Stir
int stir(int time){
digitalWrite(23,LOW); // Release Brake Stir Motor
Serial.print("Brake On ");
for (int motorspeed = 0; motorspeed < stir_speed; motorspeed++) {
analogWrite(44, motorspeed);// Ramp up speed
Serial.print("motorspeed = ");
Serial.println(motorspeed);
delay(4);
}
//motor at speed start counting
Serial.print("motorspeed = MAX ");
static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
// (static variables are initialized once and keep their values between function calls)
if (millis() - lastTick >= 1000) {
lastTick = millis();
second++;
Serial.print("Second = ");
Serial.println(second);
if (second > time){ // Count over decel motor
Serial.print("Time Out");
for (int motorspeed = stir_speed; motorspeed >= 0; motorspeed--) {
analogWrite(44, motorspeed); //Ramp down
Serial.print("motorspeed = ");
Serial.println(motorspeed);
delay(4);
}
Serial.print("motorspeed = MIN ");
digitalWrite(23, HIGH);// Set Brake stir Motor
Serial.print("Brake On ");
}
}
delay(1000);
}