Declare variables in setup()

code : http://nopaste.info/79b3fca441.html

Hi ! Quick question: arduino.cc tells me to declare all my variables in setup() . Above you see the beginning of my programm. It works like this, but as soon as i take setup() from #62 to #1 the variables i declared in setup() are not longer known in the rest of my programm. Do static variables have to be declared outside the setup() function ?

Thanks Stephan

arduino.cc tells me to declare all my variables in setup() .

Where does it say this ?

Do static variables have to be declared outside the setup() function ?

No but global variables do. Any variable declared in setup can only be used in setup.

Are you sure they did not mean initialise and not declare?

s_smaier: code : http://nopaste.info/79b3fca441.html

Hi ! Quick question: arduino.cc tells me to declare all my variables in setup() . Above you see the beginning of my programm.

How about posting it right here? Inside code tags, please.

Grumpy_Mike:

Do static variables have to be declared outside the setup() function ?

No but global variables do. Any variable declared in setup can only be used in setup.

Are you sure they did not mean initialise and not declare?

thank you ! big difference ;) but can i also declare and initialise the variable outside of setup ? I mean... it works, but is it ok to do it this way ?

can i also declare and initialise the variable outside of setup ?

Yes then they are called global variables and can be accessed in any function. Good coding practice says use as few of these as possible to avoid one function changing something that another is expecting to remain unchanged.

thanks !

I think useful if you read this: http://www.cplusplus.com/doc/tutorial/variables/

Section "scope of variables"