help with Variables

hi
if i have i>=0 and i<=1000 and (i) is increasing like i++;
and my analog read is increasing too due to (i) increasing but not identically
analog read maybe 500 at i = 600 or analog read maybe 500 at i = 300

how can I make (i) increase or decrease until analog read is 500 or any value that I chose :o

What? What are you talking about? analogRead reads the voltage on a pin coming from some outside source. How is that supposed to be related to this variable i?

Try to be less abstract and more concrete. What are we actually talking about here?

Please read this post:

Useful links - check here for reference posts / tutorials

...especially the first part, How to Ask a Good Question.

We have no idea how to solve your problem because we can't see it. Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. Or perhaps open it in WordPad, which isn't very good for looking at code. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Many questions can be answered by reading the documentation which is provided with the IDE, available under the help tab, or online here.

There are many other things that programmers do to make their code understandable. Please do them, as a courtesy to the members who volunteer their time to help you here. One is to use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Another is to give things descriptive names. You can name numerical constants, pin numbers, variables and many other things in this way.

int Setpoint = 500;
const int InputPin = A0;
void loop() {
    static i = 0;
    if (analogRead(InputPin) < Setpoint)
        i++;
    if (analogRead(InputPin) > Setpoint)
        i--;
}

If you want the result to be more precise you can use the PID library to dampen oscillations.

@ johnwasser
Thanks man it was a grate :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

Karma for john, for understanding what the hell the OP meant.

The OP has started another thread here http://forum.arduino.cc/index.php?topic=398000 no doubt because he has discovered that oops, timing matters.