Hi Guys,
I am aware that Arduino, like all single core CPU's can only do one thing at a time but what I want to do seems like something that must have been accomplished pre multi-core.
I have to control 15 motors independently but for the sake of this argument we'll focus on just two. I have to control the acceleration, deceleration, the top speed it reaches, the length of time it stays there etc. of each motor independently and at the same time!
At the moment with this following code, I have to wait for 'motor 1' to accelerate and decelerate before 'motor 2' starts but I need them to do it at the same time. What is the best way to do this? Or is it impossible?
//Initialize Motor 1
int InA1 = 2;
int InB1 = 4;
int PWM1 = 3;
//Initialize Motor 2
int InA2 = 11;
int InB2 = 10;
int PWM2 = 9;
void setup()
{ pinMode (InA1, OUTPUT);
pinMode (InB1, OUTPUT);
pinMode (PWM1, OUTPUT);
pinMode (InA2, OUTPUT);
pinMode (InB2, OUTPUT);
pinMode (PWM2, OUTPUT);
Serial.begin(9600);
}
void loop ()
{
//MOTOR 1
//Motor 1 Direction
digitalWrite(InA1, HIGH);
digitalWrite(InB1, LOW);
//Motor 1 Acceleration Control
{for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5){
analogWrite(PWM1, fadeValue);
delay(10000); }
}
//Motor 1 Run Time
delay(10000)
//Motor 1 Decceleration Control
{for(int fadeValue = 0 ; fadeValue <= 255; fadeValue -=5){
analogWrite(PWM1, fadeValue);
delay(10000); }
}
//Motor 1 Stop Time
delay(10000)
}
//MOTOR 2
//Motor 2 Direction
digitalWrite(InA2, HIGH);
digitalWrite(InB2, LOW);
//Motor 2 Acceleration Control
{for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5){
analogWrite(PWM2, fadeValue);
delay(10000); }
}
//Motor 2 Run Time
delay(10000)
//Motor 2 Decceleration Control
{for(int fadeValue = 0 ; fadeValue <= 255; fadeValue -=5){
analogWrite(PWM2, fadeValue);
delay(10000); }
}
//Motor 2 Stop Time
delay(10000)
}
}
Many thanks,
Pete