Go Down

Topic: Help with a project (Read 826 times) previous topic - next topic


hey guys, i'm kinda new on Arduino Programmation, so.. i'm working out on a project and i need your help

      -  i have to read the value of a Potentiometer and turn a LED ON for a second when the value of the potentiometer is less or equal to 500, and he must turn off even if the value still less or equal than 500, and when the value became more or equal to 501 the led must TURN ON again for a second even if the value still more or equal to 501.

that's it


What do you need help with? If you are just getting started, go through some of the tutorials. There are examples for blinking a LED and reading an analog input. If you have specific questions or problems ask them and we will help.


As a hint, you'll need to keep track of the previous value, to compare to the current value. Perform the action only when the new and old values are not on the same side of 500.
The art of getting good answers lies in asking good questions.


You actually didn't fully specify the operation.
Suppose everything starts out with pot at 600 and the led is off.
Now move the pot to 400 for only half a second, and then back up to 600 and remain.
Which of these does the led do?

A.  On for 1 sec and then remain off.  The downward transition gets detected but not the upward one.


B.  On for 1.5 seconds.   The downward transition starts 1 sec of led on.  Halfway through, the upward transition starts another 1 sec of on.

The implementation depends on what you want to accomplish.  You can use the delay() function for A. Changes happening during the delay are lost.
For B you would need to continually read the pot and the millis time in a loop as in Paul's hint.  You have state variables "On" and "TimeOfOn" which you set whenever the previous and current values show a desired transition.   As you are reading values in loop, if the state is On, you subtract the time difference and, if it is greater than 1 sec, you set the state variable and led to off (0).   Within the loop you always set the previous time and pot value to the just measured ones.

Go Up