Go Down

Topic: INT (Read 622 times) previous topic - next topic

sigilwig444

Hello, is there a way to do an integer that lasts throughout the whole code? For example when you use and int in setup you can't use it again. If there a type of integer that would allow me to do it again?

guix

#1
Jul 29, 2013, 03:29 am Last Edit: Jul 29, 2013, 03:31 am by guix Reason: 1
Just put it at the top of your code, that will make it a global variable :)

http://arduino.cc/en/Reference/scope

sigilwig444


Just put it at the top of your code, that will make it a global variable :)

http://arduino.cc/en/Reference/scope


Thank you!

guix

NP :)

After re-reading your post, I realize you may be interested by the "static" keyword, example:
Code: [Select]

void loop()
{
  static int i;
  i++;
}


Using static, the i variable will not be reset to 0 every loop()

Go Up