I am not used to programming, and need a bit of help with this.
The problem i got is that i want "motor1" to run for 1 second and when it has run for one second it turns off, and then "motor2" runs for 1 second. But what happends right now is that "motor1" will run for 2 seconds and when it has run for 1 second "motor2" starts and runs for 1 second.
It is a bit hard to explain, but i hope you understand what i am asking for. Is there some type of command i can put between the loops to make the first engine stop or something like that?
void motor1loop()
{
digitalWrite(motor1fwd, HIGH);
digitalWrite(motor1rev, LOW);
delay(1000);
}
void motor2loop()
{
int lightLevel3 = analogRead(fotodiod3);
int lightLevel4 = analogRead(fotodiod4);
lightLevel3 = map(lightLevel3, 0, 1023, 0, 255);
lightLevel4 = map(lightLevel4, 0, 1023, 0, 255);
int y = lightLevel3 - lightLevel4;
{
if (y < -25)
{
digitalWrite(motor2fwd, HIGH);
digitalWrite(motor2rev, LOW);
delay(1000);
}
else if (y > 25)
{
digitalWrite (motor2fwd, LOW);
digitalWrite(motor2rev, HIGH);
delay(1000);
}
else
{
analogWrite (motor2fwd, LOW);
analogWrite(motor2rev, LOW);
delay(1000);
}