Hello everyone,
I have basically two problems.First, I want to repeat a line of code in the "if" statement a number of times.
Second, I want a led to turn on according to the sensor value at the same time the rest of the code runs. I already looked at the blinkwithouthdelay example but I don't understand how to use it with "if" and "else".
Here's the code:
const int m1r=3;
const int m1l=4;
const int m2f=9;
const int m2b=11;
const int threshold = 200;
const int threshold1= 900;
const int sensorMin = 100;
void setup(){
pinMode(m1r, OUTPUT);
pinMode(m1l, OUTPUT);
pinMode(m2f, OUTPUT);
pinMode(m2b, OUTPUT);
}
void loop(){
int analogValue = analogRead(0);
int analogValue1 = analogRead(1);
//Motor control
if (analogValue > threshold) {
digitalWrite(m2b,LOW);
digitalWrite(m2f,HIGH);
delay(1000);
[b]//Here I want to repeat the following lines six times[/b]
digitalWrite(m1r,HIGH);
digitalWrite(m1l,LOW);
digitalWrite(m2b,LOW);
digitalWrite(m2f,HIGH);
delay(700);
digitalWrite(m2b,HIGH);
digitalWrite(m2f,LOW);
digitalWrite(m1r,LOW);
digitalWrite(m1l,HIGH);
delay(1000);
digitalWrite(m2b,HIGH);
digitalWrite(m2f,LOW);
digitalWrite(m1r,LOW);
digitalWrite(m1l,HIGH);
delay(1000);
}
[b]//Until here[/b]
else{
digitalWrite(m2f,LOW);
digitalWrite(m2b,HIGH);
digitalWrite(m1r,HIGH);
digitalWrite(m1l,HIGH);
}
}
An example would be appreciated.