int count = 0; //initialize count
int threshold;
void setup() {
// Start serial communication
Serial.begin(9600);
}
void loop() {
// Prompt for the threshold
Serial.print("Enter the threshold ... ");
// Wait for input
while (Serial.available() == 0) {
// Do nothing until input is available
}
// Read the integer value from the input
threshold = Serial.parseInt();
// Clear the serial buffer to avoid extra characters like '\n'
while (Serial.available() > 0) {
Serial.read(); // Flush any leftover characters
}
// Print the threshold for verification
Serial.println(threshold);
// Count until the threshold is reached
while (count < threshold) {
Serial.print(count);
Serial.print(" which is less than ");
Serial.println(threshold);
count++;
}
// If the count reaches the threshold
if (count == threshold) {
Serial.print(count);
Serial.print("----------");
Serial.println("Finished");
// Reset count for the next iteration
count = 0;
}
// Delay to avoid rapid repeats
delay(500);
}