' ' was not declared in this scope

I'm tring to mess around with the serial.print function and would like to see the values from a potentiometer. However, I get a compile error 'val' was not declared in this scope.

image

This seems pretty similar to how they have it on page 59 of prject 4 in Project book but I still can't figure out what im doing incorrectly.

You declared "val" in the "setup()" function, so you can only access it within the "setup()" function.

Not there either.

Oh, you're right.

I get a clean compile with:

image

My concern is that every time this loops back it will reset the value to 0. Is this the case?

Yes. You need to define "val" as a global variable if you do not want that.

What's wrong with a simple

int val = analogRead (pin);

?

(Please - posting pictures is just a waste of time. Post code, in code tags)

Would that be a problem?

You might also do this

int val = analogRead(....

I don't think that would be a problem to use it that way.

I was using the Project Book as a reference point for the last time I did an analogRead.

Thanks for the suggestion on using code tags; as I'm just beginning to learn the Arduino hardware and software, I'm also learning the formatting for this forum.

A lot of us have never seen that.

And you then, almost immediately, replace that 0 with the result of your analogRead(). No problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.