for (int i = 0; i = 0; i++) // we turn the motor
{
analogWrite(3, i);
delay(10);
for (int i = 0; i = 50; i++)
{
analogWrite(3, i);
delay(10);
}
}
buttonState = digitalRead(buttonPin);// reading of the sensor
for (int i = 0; i = 50; i++); // here is the line that i modified
{
analogWrite(3, i);
delay(10);
buttonState = HIGH;
if (buttonState == HIGH) //si quelquechose est detecte
{
digitalWrite(ledPin, HIGH); //on allume la LED
for (int i = 0; i = 0; i++) // we turn the motor
{
analogWrite(3, i);
delay(10);
}
}
}
}
But i already see this line but i tried to make something like the' if 'that are in you're code:
if (motorMoving == false) {
analogWrite(motorPin, pwmValue);
motorMoving = true;
}
if (motorMoving == true) {
sensorVal = digitalRead(sensorPin);
if (sensorVal == HIGH) {
analogWrite(motorPin, 0);
motorMoving = false;
}
}
}
But it make error because i think the:
for (int i = 0; i <= 50; i++)
doesn't work with the 'if'
But i need the 'if' to try to make my code similar of yours...