i have some problem to ask. How to make the program of stepper motor and DC motor run at the same time while controlling the speed of DC motor using a potentiometer. I have tried to write the program, but it seem cannot run at the same time. Can I know where is wrong or what should added in my coding?Thanks for reply and appreciate always...This is my coding.
#include <LiquidCrystal.h>
#include <Stepper.h>
#define motorSteps 500 // change this depending on the number of steps
// per revolution of your motor
#define motorPin1 2 //stepper motor pwm1
#define motorPin2 3 // stepper motor pwm2
#define motorPin3 4 // stepper motor pwm3
#define motorPin4 5 // stepper motor pwm4
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
int ledPin3= 36;
int forwardledPin=40;
int reverseledPin=39;
int stopledPin = 38;
int pot = A2;
int motorPin = 9;
int speed = 0;
boolean shade_open = false;
boolean shade_close = true;
Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);
void setup ()
{
myStepper.setSpeed(60);
Serial.begin(9600);
pinMode(ledPin3,OUTPUT);
pinMode(forwardledPin,OUTPUT);
pinMode(reverseledPin,OUTPUT);
pinMode(stopledPin,OUTPUT);
pinMode(motorPin, OUTPUT);
pinMode(pot, INPUT);
digitalWrite(motorPin, HIGH);
}
void loop ()
{
digitalWrite(ledPin3,HIGH);
speed= analogRead(pot);
speed = map(speed, 0, 1023, 0, 255);
analogWrite (motorPin, speed);
Serial.print(speed);
delay(500);
if((motorPin==HIGH)&&(speed >50)){ //most strong wind 4.5ms-1 on dec
digitalWrite(forwardledPin,LOW);
digitalWrite(reverseledPin,LOW);
digitalWrite(stopledPin,LOW);
lcd.clear();
lcd.print(" STRONG WIND... ");
delay(5000);
lcd.clear();
lcd.print(" CLOSE SHADE ");
delay(3000);
digitalWrite(reverseledPin,HIGH);
if(shade_open){ //if shade close, then open it
myStepper.step(-2000);
shade_open = false;
shade_close = true;
}
digitalWrite(reverseledPin,LOW);
digitalWrite(stopledPin,HIGH);
}
if((motorPin==HIGH)&&(speed <50)){ // open shade if no strong wind
digitalWrite(stopledPin,LOW);
digitalWrite(forwardledPin,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" NORMAL WIND ");
lcd.setCursor(0,1);
lcd.print(" OPEN SHADE ");
delay(5000);
digitalWrite(forwardledPin,HIGH);
if(shade_close){ //if shade open, then close it
myStepper.step(2000);
shade_open = true;
shade_close = false;
}
digitalWrite(forwardledPin,LOW);
digitalWrite(stopledPin,HIGH);
}
}