I want to blink LED on pin 13 in a sequence...
but without delay...
This is the way I want it to blink but I have written the code with delay...
{
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(1000);
I want to blink LED on pin 13 in a sequence...
but without delay...
This is the way I want it to blink but I have written the code with delay...
{
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
delay(1000);
It depends on how complicated your blinking pattern is. If it's just a different length for on and off, you can do it easily with something like this.
loop () {
static unsigned long starttime;
static int ledstate = LOW;
if (ledstate == HIGH && millis() - starttime > 50) {
ledstate = LOW;
digitalWrite(13, LOW);
starttime = millis();
}
else if (ledstate == LOW && millis() - starttime > 1000) {
ledstate = HIGH;
digitalWrite(13, HIGH);
starttime = millis();
}
}
The code hasn't been tested and the whole thing can be done with more terse code too. If you want more complicated patterns, better use an array with delays instead. I'm certain you'll figure out on your own how to do that if you need it.
Korman