#include // Die  TaskMacros sind hier zu finden: // https://forum.arduino.cc/index.php?topic=415229.0 const bool AUS = false; const bool EIN = true; // Pin def const byte licht  = 13; const byte wasser = 12; void tueWasser() {   taskBegin();   taskPause(3L*60L*60L*1000L); // 3H wa… Answer from combie on forum.arduino.cc
🌐
AZ-Delivery
az-delivery.de › home › instructions, projects and news › instructions, projects and news
Blink Sketch ohne delay()
August 1, 2018 - The use of delay(1000) in the Blink Sketch has a big disadvantage: the microcontroller waits one second (1000 ms), and can't do anything else during this time.
Discussions

Blinken ohne delay() mit 2 Taster und 2 LEDs
Ich bin noch ein Arduino-Anfänger, ... 2 drücke, hört LED1 auf zu blinken und leuchtet nur noch, jedoch fängt dann LED2 an zu blinken Ich muss dieses Projekt ja ohne delay() machen da ja...... More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
November 18, 2015
mehrfachzeiten, blink without delay
Hi, hab mal wieder ein problemchen mit dem programmiern, es geht um ein Positionslicht das per Taster ein und ausgeschalten wird, Ich bekomm es aber einfach nicht hin 3fach Zeiten zu Progammiern, mit delay kein Problem, aber es sollen später noch weitere funktionen hinzukommen. More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
May 4, 2019
LED blink, no delay(), one line of code
Sneaky, consider it stolen, I have a "something needs checking" notification system that flashes an led/pulses a beeper on every gadget that subscribes to the notification topic, this is a neater method than I currently use. More on reddit.com
🌐 r/arduino
146
416
April 30, 2021
BlinkwithoutDelay - Die Nachtwächtererklärung
Ich wurden gebeten, die Erklärung des BlinkWithoutDelay hier nochmal reinzustellen. Am Beispiel eines Wachmanns, der seine Runden dreht, wird in einfacher und eingängiger Weise erklärt, wie man ohne delay() zeitliche Abfolgen programmieren kann. (an die Profis: es geht auch einfacher, es ... More on forum.arduino.cc
🌐 forum.arduino.cc
19
2
September 13, 2016
🌐
Noethlich
moba.noethlich.info
Programmieren ohne ‚delay‘ | Modellbahn-Seiten von Bodo Noethlich
Für den Einsatz auf einem Arduino sind natürlich auch mehr als 5 LEDs möglich und die Portnummern anzupassen. Das Programm ist nur unwesentlich größer, kann aber nun 5 LEDs unabhängig mit verschiedenen Frequenzen und unsymmetrisch (High-Low-Verhältnis) blinken lassen, weil pausenlos nacheinander für alle LEDs geprüft wird, ob sie geschaltet werden müssen – das ist mit Verwendung von ‚delay‘ so nicht mehr zu realisieren.
🌐
Arduino Forum
forum.arduino.cc › international › deutsch
Blinken ohne delay() mit 2 Taster und 2 LEDs - Deutsch - Arduino Forum
November 18, 2015 - Ich bin noch ein Arduino-Anfänger, ... 2 drücke, hört LED1 auf zu blinken und leuchtet nur noch, jedoch fängt dann LED2 an zu blinken Ich muss dieses Projekt ja ohne delay() machen da ja......
🌐
Shelvin
shelvin.de › arduino-programmierung-10-led-blinken-ohne-delay
Arduino Programmierung #10 – LED blinken ohne delay()
January 10, 2022 - // LED blinken lassen ohne delay() int LED=13; unsigned long neuMillis, altMillis, intervall=200; bool ledStatus; void setup() { pinMode(LED, OUTPUT); altMillis=0; } void loop() { neuMillis = millis(); if( (neuMillis - altMillis) >= intervall){ altMillis = neuMillis; ledStatus = !ledStatus; digitalWrite(LED, ledStatus); } // hier läuft der Programmcode weiter }
🌐
Arduino Forum
forum.arduino.cc › international › deutsch
mehrfachzeiten, blink without delay - Deutsch - Arduino Forum
May 4, 2019 - Hi, hab mal wieder ein problemchen mit dem programmiern, es geht um ein Positionslicht das per Taster ein und ausgeschalten wird, Ich bekomm es aber einfach nicht hin 3fach Zeiten zu Progammiern, mit delay kein Problem, aber es sollen später noch weitere funktionen hinzukommen.
Find elsewhere
🌐
Arduino Forum
forum.arduino.cc › international › deutsch
BlinkwithoutDelay - Die Nachtwächtererklärung - Deutsch - Arduino Forum
September 13, 2016 - Ich wurden gebeten, die Erklärung des BlinkWithoutDelay hier nochmal reinzustellen. Am Beispiel eines Wachmanns, der seine Runden dreht, wird in einfacher und eingängiger Weise erklärt, wie man ohne delay() zeitliche Abfolgen programmieren kann. (an die Profis: es geht auch einfacher, es sind syntaktische Unsauberkeiten drin.
🌐
Herbrand
herbrand.org › tutorials › arduino › timer-ohne-delay-funktion
Timer ohne Delay-Funktion - bei herbrand.org
Für umfangreichere Anwendung bietet sich an, einen der integrierten Timer des Arduino zu verwenden. Damit werden die v. g. Probleme vermieden. In diesem dokumentierten Beispiel blinken zwei LEDs mit unterschiedlichen On/Off-Zeiten: /* Beispiel für 2 LEDs mit unterschiedlichen Blinkzeiten (ohne Delay) * Version 1.0 * Datum: 20.11.2019 * Autor: Hans M.
🌐
Reddit
reddit.com › r/arduino › led blinking without delay
r/arduino on Reddit: Led blinking without delay
May 22, 2022 -

Hello, I need a little bit of help.

The guides I've seen either have 1 led blinking or multiple at the same time which doesn't really help me, and I've seen no real solutions for a sequential blink without using delays...or none that make any sense to me.

I can't use delays because I need them to do one thing while waiting for an input then do something else. The functioning code I have right now is:

void blink1(){
digitalWrite(Led1, HIGH);
delay(250);
digitalWrite(Led1, LOW);
digitalWrite(Led2, HIGH);
delay(250);
digitalWrite(Led2, LOW);
digitalWrite(Led3, HIGH);
delay(250);
digitalWrite(Led3, LOW);
delay(500);

}
void blink2(){
digitalWrite(Led1, HIGH);
digitalWrite(Led2, HIGH);
digitalWrite(Led3, HIGH);
delay(250);
digitalWrite(Led1, LOW);
digitalWrite(Led2, LOW);
digitalWrite(Led3, LOW);
delay(250);
}

I have it setup like this because the eeprom has an initial value stored, In the loop it looks at the eeprom value and calls the specific blink. When there's an input it updates the eeprom value and then will call the other blink... had to use eeprom because I need it to save that state in the event of a poweroff. That's all working fine I just can't figure out how to make the LED's blink like this without using delays.

Thank you!

Top answer
1 of 4
3
Try playing with this. It compiles but is completely untested. It basically supports both of your blink scenarios and switches between the two with the press of a button (modify your input and output pins as needed). It also flashes the built-in LED on the board continuously to further demonstrate doing more than one thing at a time. Again, untested... const uint8_t pinLED1 = 2; const uint8_t pinLED2 = 3; const uint8_t pinLED3 = 4; const uint8_t pinSw = 5; void setup( void ) { pinMode( pinSw, INPUT_PULLUP ); pinMode( pinLED1, OUTPUT ); pinMode( pinLED2, OUTPUT ); pinMode( pinLED3, OUTPUT ); pinMode( LED_BUILTIN, OUTPUT ); }//setup void loop( void ) { toggleBuiltIn(); if( digitalRead( pinSw ) == HIGH ) blink1(); else blink2(); }//loop void toggleBuiltIn( void ) { static bool state = false; static uint32_t tBuiltIn = 0ul; uint32_t tNow = millis(); if( (tNow - tBuiltIn) >= 300ul ) { tBuiltIn = tNow; state ^= true; digitalWrite( LED_BUILTIN, (state == true) ? HIGH:LOW ); }//if }//toggleBuiltIn void blink1() { static uint8_t state = 0; static uint32_t tBlink1 = 0ul, tDelay1 = 0ul; uint32_t tNow = millis(); if( (tNow - tBlink1) >= tDelay1 ) { tBlink1 = tNow; switch( state ) { case 0: digitalWrite(pinLED1, HIGH); tDelay1 = 250ul; state++; break; case 1: digitalWrite(pinLED1, LOW); digitalWrite(pinLED2, HIGH); tDelay1 = 250ul; state++; break; case 2: digitalWrite(pinLED2, LOW); digitalWrite(pinLED3, HIGH); tDelay1 = 250ul; state++; break; case 3: digitalWrite(pinLED3, LOW); tDelay1 = 500ul; state = 0; break; }//switch }//if }//blink1 void blink2() { static uint8_t state = 0; static uint32_t tBlink2 = 0ul; uint32_t tNow = millis(); if( (tNow - tBlink2) >= 250ul ) { tBlink2 = tNow; switch( state ) { case false: digitalWrite(pinLED1, HIGH); digitalWrite(pinLED2, HIGH); digitalWrite(pinLED3, HIGH); state = true; break; case true: digitalWrite(pinLED1, LOW); digitalWrite(pinLED2, LOW); digitalWrite(pinLED3, LOW); state = false; break; }//switch }//if }//blink2
2 of 4
2
Have a play around with this: https://wokwi.com/projects/328810376987673171 Change the values in the lines like: nextTime1 = millis() + random(400,1200); ...then click the play/restart button at the top of the right side panel. It's OK..you can't break my demo, it's locked for saving. If you do FUBAR it, then refresh the page. The line above says generate a random number between 0.4 and 1.2 seconds, add that to the current milliseconds and that becomes the duration of the blink. This demo was for someone else who needed randomised timing on 2 LEDs and a set time on a 3rd There are 2 randoms and a static, and a pushbutton toggled LED (yes..I know it's not debounced!) and that shows the benefits of not using delay to do a thing in the middle if a sequence of other things ocurring. If you needed to use more than 3 or 4, the code gets a bit messy so might pay to look at using arrays to store values and reference them by their array index. Having said that last part, I rewrote it to use arrays, makes it a lot easier to scale up
🌐
Newbiely
newbiely.de › tutorials › arduino-mega › arduino-mega-led-blink-without-delay
Arduino - LED - Blinken ohne Delay
Die Schönheit der Kombination von LEDs und Buttons in nicht-blockierendem Code liegt darin, dass sie reale Reaktionsfähigkeit demonstriert - Ihre LED kann in einem gleichmäßigen Rhythmus blinken, während Ihr Arduino wachsam bleibt und bereit ist, sofort auf Button-Drücke zu reagieren. In traditionellem blockierendem Code mit delay() wird Ihr Arduino während der Delay-Perioden "taub" für Button-Drücke.
🌐
Assiss
assiss.github.io › arduino-zhcn › cn › Tutorial › BlinkWithoutDelay.html
Arduino - BlinkWithoutDelay
The code below uses the millis() ... its current program, to blink an LED. /* Blink without Delay Turns on and off a light emitting diode(LED) connected to a digital pin, without using the delay() function....
🌐
Arduino Forum
arduinoforum.de › arduino-Thread-Blink-Without-Delay-mal-anders-erklärt
Blink Without Delay - mal anders erklärt
October 31, 2015 - Hallo, immer wieder stören Delays den Programmablauf. Wie man diese Delays vermeidet ist im Tutorial Blink Without Delay erklärt. Scheinbar kommt aber nicht jeder mit dieser Anleitung gut zurecht. Vie
🌐
GitHub
github.com › arduino › arduino-examples › blob › main › examples › 02.Digital › BlinkWithoutDelay › BlinkWithoutDelay.ino
arduino-examples/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino at main · arduino/arduino-examples
without using the delay() function. This means that other code can run at the · same time without being interrupted by the LED code. · The circuit: - Use the onboard LED.
Author   arduino
🌐
Arduino Getting Started
arduinogetstarted.com › tutorials › arduino-led-blink-without-delay
Arduino - LED - Blink Without Delay | Arduino Getting Started
1 week ago - In the previous tutorial, we learned to blink LED by using the delay method. That method blocks Arduino from doing other tasks. In this tutorial, we are going to learn another method to blink LED without blocking other tasks. The detail instruction, code, wiring diagram, video tutorial, ...
🌐
Arduino Forum
forum.arduino.cc › projects › programming
LED blink without delay from function - Programming - Arduino Forum
February 5, 2021 - I wanted to further expand this ... ms, char color); Basically, the function should let an LED blink for 'count' times, with an 'ms' interval without interrupting / halting the loop function....
🌐
Programming Electronics Academy
programmingelectronics.com › home › tutorial 16: blink an led without using the delay() function
Tutorial 16: Blink an LED Without using the delay() Function - Programming Electronics Academy
February 14, 2016 - /* Blink without Delay Turns on and off a light emitting diode (LED) connected to a digital pin, without using the delay() function. This means that other code can run at the same time without being interrupted by the LED code.
🌐
Arduino Forum
forum.arduino.cc › international › deutsch
Blink without delay - Deutsch - Arduino Forum
November 8, 2020 - Hallo zusammen, Ich möchte eine Ampel nachbauen, die wie eine echte im Straßenverkehr läuft (mit blinken und allem) Ich habe ein Node MCU Board auf dem ein Sketch (im Anhang) läuft der drei Relais schaltet, welche jeweils eine Glühbirne schalten. (habe das bisher mit Delay realisiert) Jetzt sollten aber über die Blink App noch ein oder zwei Inputs in form von Schaltern kommen.