I need to blink an LED while there is a delay going on.
The delay needs to be there for a timing aspect of the sketch.
I know there is blink whithout delay but, I am using a delay.
delay() tells the processor to sit in a loop doing nothing until the delay-time is up. In most real-world programs you want to avoid that.
I can get the sketch to work how i want by turning the LED on, waiting a second, then turning it off.
This works, I just wondered if there was a neater way that I could do the same thing.
Whenever you find your program doing the same thing over-and-over, it's time for a loop. Besides the loop() function, the [u]for-loop[/u] is probably the most common. There are also while() loops and do-while loops.
You can change variables inside the loop - The simplest example is incrementing a variable to count how many times you go through the loop, or you can "sequence" LEDs by switching-on a different LED each time through the loop, etc. In your case, you can "toggle" the state of the LED each time through the loop if the time is up), so that if it's on it turns-off, and if it's off it turns-on. And, you can "break out" of the loop depending on the conditions you set-up.
Loops, conditional branching (if-statements, etc.), and math are the 3 basic concepts that make programming worthwhile!