Listing 7 3 StaticVariable

From ArduinoInfo
Jump to navigation Jump to search
_7_3_StaticVariable

/* Listing 7-3. Using the static Storage Class. */
void setup() {
  Serial.begin(9600);
}

void loop() {
  while (true) {
    Serial.println(MyCounter());
  }
}

int MyCounter()
{
   static int counter = 0;
   // do some stuff...
   return ++counter;
}