I lied slightly when I said I had an Arduino. We are using them in class, and I am no longer in class. But I didn't know it was possible to print things out. That command will definitely come in handy next time.
I don't want to ever reset my counter. I want the LED to blink thrice and stop blinking. However, the code I posted was not achieving that for some reason; it was instead causing the LED to blink indefinitely.
You still have a problem with "counter" though. Once the "if" condition is exceeded, there's nothing to stop the processor from whipping through your loop at full speed 32,767 times (limit of an int) until the variable rolls over and you start blinking again.
There's a quick and dirty solution if you don't want your Arduino to do anything once the 3 blinks are over. Is that the case?
mjward:
You still have a problem with "counter" though. Once the "if" condition is exceeded, there's nothing to stop the processor from whipping through your loop at full speed 32,767 times (limit of an int) until the variable rolls over and you start blinking again.
--Michael
Ah, that makes a lot of sense. I can just use a flag, which gets set to false when n is reached the first time. I could also just stick the counter++; inside the loop. Thanks!
A "one shot blinking" or "one shot flashing" that shall occur only a certain number of times when a momentary switch button is pressed, or some other action occurs, can also be done without delay() so it is non-blocking, and also with different LED on and LED off times. Maybe the code below is useful for some other beginners.