Countdown

Hallo alle zusammen,
Ich weiss das Thema wurde schon zur genüge behandelt aber könnt ihr mir vieleicht noch mal nen Denkanstoss geben.
Ich möchte von einem Wert 10sec lang abziehen ohne mit delay zu arbeiten.

Igend wie krieg ich das nicht mehr zusammen.

Mein Vorschlag:

EndeCountdown=millis()+10999;

In einer Schleife bis Countdown Null ist:

Contdown=(EndeCountdown-millis())/1000

Countdown wird bei 999 Null.

Schleife <> gut

würde dann wohl so ausssehe:

void count_down()
{
////////////////////////////////////////////////////////////////  

EndeCountdown=millis()+10999; 

if(Contdown >= 0)
{
  Contdown=(EndeCountdown-millis())/1000;
Serial.println(Contdown);
}

}

Du musst noch dafür sorgen, dass die Endzeit nicht ständig neu gesetzt wird. Also eine Schleife oder eine Statusvariable nutzen.

Auch hier, überall wo kein delay verwendet werden soll, einfach den Blinkohnedelay Beispiel nehmen!
würde dann wohl so ausssehe:

/* 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.

 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.

 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
 modified 11 Nov 2013
 by Scott Fitzgerald


 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
const long interval = 1000;           // interval at which to blink (milliseconds)
  uint8_t timer = 10; 
void setup() {
  // set the digital pin as output:

Serial.begin(9600); 
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval && timer > 0) {
    Serial.println(timer); 
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    timer--;
  }
}