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);
}