int counter = 0; // Initialize a counter variable
int increment = 1; // Initialize the increment variable
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
Serial.println(counter); // Print the current value of the counter
counter = counter + increment; // Increment the counter
// Reverse the increment direction when limits are reached
if (counter >= 10 || counter <= 0) {
increment = -increment; // Change the direction of increment
}
delay(500); // Wait for 500 milliseconds
}