My platform is Arduino Mega 2560.
I wrote a sketch to print the value of a counter to the serial port,
and then use other applications (e.g., Matlab, or the Serial Monitor) to read the value through the serial port.
The counter can be increased correctly.
However, when the next time I connect to the serial port,
the counter will be reset to zero, and I didn’t reset or reboot the Arduino.
Could anyone please show me why the variable will reset to zero,
and how the keep the counter increasing without going back to zero?
The sample code?
static int counter = 0;
Serial.println( counter );