for(int i=0;i<1023;i++)
{
analogWrite(which, i);
}
for(int i=0;i<1023;i++)
{
analogWrite(which, i);
}
// To turn the robot left side
void turnLeft()
{
stopmotor(M2);
stopmotor(M3);
delay(5000);
Runmotor(M2);
Runmotor(M3);
}
// To turn the robot left side
void turnLeft()
{
stopmotor(M2);
stopmotor(M3);
delay(5000);
Runmotor(M2);
Runmotor(M3);
}
// To turn the robot left side
void turnLeft()
{
stopmotor(M1);
stopmotor(M4);
delay(5000);
Runmotor(M2);
Runmotor(M3);
}
// To turn the robot left side
void turnLeft()
{
stopmotor(M1);
stopmotor(M4);
delay(5000);
Runmotor(M2);
Runmotor(M3);
}
// To turn the robot left side
void turnLeft()
{
stopmotor(M1);
stopmotor(M4);
Runmotor(M2);
Runmotor(M3);
}
// To turn the robot left side
void turnLeft()
{
stopmotor(M1);
stopmotor(M4);
Runmotor(M2);
Runmotor(M3);
}
const int NUMBER_OF_MOTORS = 4;
const int motorPins [NUMBER_OF_MOTORS] = { 3, 4, 6, 9 };
const int NUMBER_OF_MOTORS = 4;
const int motorPins [NUMBER_OF_MOTORS] = { 3, 4, 6, 9 };
// Motors Initilization
for (int i = 0; i < NUMBER_OF_MOTORS; i++)
pinMode (motorPins [i], OUTPUT);
// Motors Initilization
for (int i = 0; i < NUMBER_OF_MOTORS; i++)
pinMode (motorPins [i], OUTPUT);
for (int i = 0; i < NUMBER_OF_MOTORS; i++)
stopmotor (i);
for (int i = 0; i < NUMBER_OF_MOTORS; i++)
stopmotor (i);
// Stop Motor
void stopmotor(int which)
{
digitalWrite(motorPins [which],LOW);
}
// Stop Motor
void stopmotor(int which)
{
digitalWrite(motorPins [which],LOW);
}
(Edited to add)
I also don't see what this achieves:
void Runmotor(int which)
{
for(int i=0;i<1023;i++)
{
analogWrite(which, i);
}
}
Apart from the fact that you can't go up to 1023, if you stop at 255, the time taken to do all those analogWrite is just over 2 ms. Why bother? Why not just do this:
void Runmotor(int which)
{
digitalWrite (which, HIGH);
}