controlling two dc motor and stepper motor

hi everyone

hi, i am newbie to arduino coding and i need to rotate 2 dc motor with speed variation and stepper motor at the same time. for now my coding only rotating the stepper motor after the dc motor and i will the motor rotating simultaneously at same time. can help me to resolve the issue?

thnks

the code

#include <Stepper.h>

#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 12, 9, 10, 11);
#define motor_in1  2
#define motor_in2  3
#define motor_in3  4
#define motor_in4  5
#define motorspeed1  9
#define motorspeed2  10

const int speed1;
const int speed2;

String readString;
;



void setup() 
{
Serial.begin(9600);
pinMode(motor_in1 , OUTPUT);
pinMode(motor_in2 , OUTPUT);
pinMode(motor_in3 , OUTPUT);
pinMode(motor_in4 , OUTPUT);
pinMode(motorspeed1, OUTPUT); 
pinMode(motorspeed2, OUTPUT);
myStepper.setSpeed(15);
Serial.begin(9600);



} 

void loop() 
{
 left1 (200,255);//max255
 right1(200,255);

 left2(60,255);
 right2(60,255);
 stepper4;
}
void left1 (int mspeed1,int mspeed2)
{
 analogWrite(motorspeed1, mspeed1);
 analogWrite(motorspeed2, mspeed2); 
 digitalWrite(motor_in1, HIGH);
 digitalWrite(motor_in2, LOW);
 digitalWrite(motor_in3, HIGH);
 digitalWrite(motor_in4, LOW);  
}

void left2 (int mspeed1,int mspeed2)
{
 analogWrite(motorspeed1, mspeed1);
 analogWrite(motorspeed2, mspeed2); 
 digitalWrite(motor_in1, HIGH);
 digitalWrite(motor_in2, LOW);
 digitalWrite(motor_in3, HIGH);
 digitalWrite(motor_in4, LOW);  
}

void left3 (int mspeed1,int mspeed2)
{
 analogWrite(motorspeed1, mspeed1);
 analogWrite(motorspeed2, mspeed2); 
 digitalWrite(motor_in1, HIGH);
 digitalWrite(motor_in2, LOW);
 digitalWrite(motor_in3, HIGH);
 digitalWrite(motor_in4, LOW);  
}

void right1 (int mspeed1,int mspeed2)
{
 analogWrite(motorspeed1, mspeed1);
 analogWrite(motorspeed2, mspeed2); 
 digitalWrite(motor_in1, HIGH);
 digitalWrite(motor_in2, LOW);
 digitalWrite(motor_in3, HIGH);
 digitalWrite(motor_in4, LOW);  
}

void right2 (int mspeed1,int mspeed2)
{
 analogWrite(motorspeed1, mspeed1);
 analogWrite(motorspeed2, mspeed2); 
 digitalWrite(motor_in1, HIGH);
 digitalWrite(motor_in2, LOW);
 digitalWrite(motor_in3, HIGH);
 digitalWrite(motor_in4, LOW);  
}

void right3 (int mspeed1,int mspeed2)
{
 analogWrite(motorspeed1, mspeed1);
 analogWrite(motorspeed2, mspeed2); 
 digitalWrite(motor_in1, HIGH);
 digitalWrite(motor_in2, LOW);
 digitalWrite(motor_in3, HIGH);
 digitalWrite(motor_in4, LOW);  
}

void stepper4()
{
  Serial.println("clockwise");
 myStepper.step(stepsPerRevolution);
}

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

The regular Stepper library uses blocking code so it is not suitable for doing several things at the same time unless you simply command it to make single steps. Look up the AccelStepper library.

These links may also help
Stepper Motor Basics
Simple Stepper Code

Several Things at a Time

The analogWrite() function for controlling DC motors does not use blocking code

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

stepper4;

You forgot these ()

thank you Robin2.

i have updated the coding as you mentioned above. will look into the link you share

TolpuddleSartre

you mean the coding like this ? but the coding could not be verified in IDE

void loop() 
{
  left1 (200,255);//max255
  right1(200,255);
 
  left2(60,255);
  right2(60,255);
  stepper(4);
}

Without digging in too deep, I would suggest you rename your pins to be more conducive to reading the code.

Old Code -

void right1 (int mspeed1,int mspeed2)
{
 analogWrite(motorspeed1, mspeed1);
 analogWrite(motorspeed2, mspeed2); 
 digitalWrite(motor_in1, HIGH);
 digitalWrite(motor_in2, LOW);
 digitalWrite(motor_in3, HIGH);
 digitalWrite(motor_in4, LOW);  
}

motorspeed1 could be Motor_1
and mspeed1 could be Speed_1
Motor_inX could be Stepper_A/B/C/D (not sure what they actually are but they're not inputs!)
or something similar... Guessing stepper 'phases'.

digitalWrite() to a named 'input' seems counter-intuitive...

Something like -

void right1 (int mspeed1,int mspeed2)
{
//PWM drive to motors
 analogWrite(Motor_1, Speed_1);
 analogWrite(Motor_2, Speed_2); 

// pulse sequencing to Stepper
 digitalWrite(Stepper_A, HIGH);
 digitalWrite(Stepper_B, LOW);
 digitalWrite(Stepper_C, HIGH);
 digitalWrite(Stepper_D, LOW);  
}

Overall, there are several opportunities to streamline your code - but until wee get a clearer idea of what it's meant to do - there's not much point making it more elegant.

Check out arrays[] and for() loops, as well as possibly switch() statements.