Hy guys.
Finally i reached to stop the DC engine from with a while statement.
Now i want to Print something that tells me that the look has gone through but i dont know where tu put it.
Now its inside the loop so it writes not only once. Putting after the loop bracket i get an error :-/
Any hint please?
int motorPin1=2;
int motorPin2=3;
int x = 2;
void setup(){
pinMode(motorPin1,OUTPUT);
pinMode(motorPin2,OUTPUT);
Serial.begin(9600);
}
void motorStop(){
digitalWrite(motorPin1,LOW);
digitalWrite(motorPin2,LOW);
delay(500);
}
void loop(){
while(x <= 3){
motorStop(); // Motor Stop
digitalWrite(motorPin1,HIGH); // Motor Vor
digitalWrite(motorPin2,LOW);
delay(1000);
motorStop(); // Motor Stop
digitalWrite(motorPin1,LOW); // Motor Vor
digitalWrite(motorPin2,HIGH);
delay(1000);
Serial.print(x);
x++;
}
motorStop();
Serial.print("Finish Loop");
}
I don't understand your description what kind of functionality you want to have.
What your code is doing is
stop motor
run motor clockwise for one second
stop motor
run motor counterclockwise for one second
loop does what its name says loop = looping = repeating infinetely
repeat all code
only as x contains value 4 the condition is false
if this has repeated two time because x is initialised with value 2
repeat
while(x <= 3){
the condition is false
(4 <= 3) evaluates to false
=> code inside the while-loop is not executed
the code below the while-loop will be executed
This means make the execution of the serial-message conditional
As a recommendation for future postings describe the wanted functionality in this way no programming-terms
just everyday-words
but describe each single step of what shall happen