نقل قول نوشته اصلی توسط amin_jafarvand نمایش پست ها

کمک !!! چطوری می تونمبگم استپر موتور 5 ثانیه ساعتگرد و 5 ثانیه پاد ساعتگرد بچرخه؟ من برنامه زیر رو به هزار بدبختی نوشتم سرعت موتور و جهت گردشش رو هم با سنسور کنترل می کنم ولی نمی تونم بگم اگه ساعتگرد می چرخی بیشتر از 5 ثانیه نچرخ و برعکس؟!
این فایل برنامه هست بگید کجاش باید اضافه کنم خیلی خیلی خیلی نیاز دارم مرسی
[LEFT][RIGHT][CENTER]//declare variables for the motor pins
int motorPin1 = 8; // Blue - 28BYJ48 pin 1
int motorPin2 = 9; // Pink - 28BYJ48 pin 2
int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
int motorPin4 = 11; // Orange - 28BYJ48 pin 4
// Red - 28BYJ48 pin 5 (VCC)

int motorSpeed = 0; //variable to set stepper speed
int sensorValue = 0; //potentiometer connected to A0
long int currentMillis;


//////////////////////////////////////////////////////////////////////////////
void setup() {
//declare the motor pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){

sensorValue = analogRead(A0); // read the value of the potentiometer
Serial.println(sensorValue); // View full range from 0 - 1024 in Serial Monitor
if (sensorValue < 535){ // if potentiometer reads 0 to 535 do this
motorSpeed = (1); //scale potValue to be useful for motor

clockwise(); //go to the ccw rotation function
delay(0);

}
else { //value of the potentiometer is 512 - 1024
motorSpeed = (1); //scale potValue for motor speed
counterclockwise(); //go the the cw rotation function
delay(0);
}
}
درود بر شما
این اسکچ با فرمتی که داره به کارتون نمیاد، یعنی شما نمیتونید این interval هایی رو که میخواین توی چرخه loop بیارین. چون زمانبندیتون به هم میریزه. برای هر کدوم از کارایی که میخواین انجام شه باید void جداگونه تعریف کنین.
لینک زیر رو مطالعه کنید و فرمت برنامتون رو مشابه اون تغییر بدین:
Demonstration code for several things at the same time