Motor and sensor

Swaggydogy:
Hi you're code is interresting but i don't understand what you're saying about the analogRead()

Sorry that was a stupid mistake. I meant analogWrite(). I have corrected Reply #17

Swaggydogy:
also i don't understand how you're code work...

I see that you're replace the int (i = 0; i=50; i++) by an fonction: motorMoving

motorMoving is not a function. It is just a boolean variable that can be either true or false and its purpose is to keep track of the state of the system. You can create the variable in the normal way at the top of your program with

boolean motorMoving = false;

The way you identify a function call is by the () brackets. If motorMoving was a function it would have appeared as motorMoving()

...R