Tutorial.BlinkWithoutDelay History

Hide minor edits - Show changes to markup

December 06, 2013, at 12:16 PM by Roberto Guido -
Added line 19:
Deleted line 21:
December 06, 2013, at 12:14 PM by Roberto Guido - corrected link for example on GitHub, thanks to Rafael Martin for report
Changed lines 20-21 from:
to:
December 01, 2011, at 04:24 AM by David Cuartielles -
Changed lines 20-21 from:
to:
June 01, 2010, at 02:47 PM by Equipo Traduccion -
Changed lines 1-2 from:

Ejemplos > Digital E/S

to:

Ejemplos > E/S (I/O) Digital

June 01, 2010, at 01:20 PM by Equipo Traduccion -
June 01, 2010, at 01:20 PM by Equipo Traduccion -
Changed lines 5-6 from:

Alguna vez puede ser necesario hacer parpadear un LED (o alguna otra cuestión visible) al mismo tiempo que se hacen otras cosas (como controlar la pulsación de un botón). Esto implica no poder utilizar delay(), o todo se pararía mientras el LED parpadea. Aquí tienes un código que muestra cómo hacer parpadear el LED sin usar delay(). Controla la última vez que se encendió o apagó el LED. Entonces, cada vez que pasa por el bucle() compara si ha transcurrido un intervalo suficiente de tiempo y si es así, apaga el LED si estaba encendido o viceversa.

to:

En ocasiones puede ser necesario hacer parpadear un LED (o alguna otra cuestión visible) al mismo tiempo que se hacen otras cosas (como controlar la pulsación de un botón). Esto implica no poder utilizar delay(), o todo se pararía mientras el LED parpadea. Aquí tienes un código que muestra cómo hacer parpadear el LED sin usar delay(). Controla la última vez que se encendió o apagó el LED. Entonces, cada vez que pasa por el bucle() compara si ha transcurrido un intervalo suficiente de tiempo y si es así, apaga el LED si estaba encendido o viceversa.

June 01, 2010, at 01:20 PM by Equipo Traduccion -
Changed lines 5-9 from:

Alguna vez puede ser necesario hacer parpadear un LED (o alguna otra cuestión visible) al mismo tiempo que se hacen otras cosas (como controlar la pulsación de un botón). Esto implica no poder utilizar delay() Sometimes you need to blink an LED (or some other time sensitive function) at the same time as something else (like watching for a button press). That means you can't use delay(), or you'd stop everything else the program while the LED blinked. Here's some code that demonstrates how to blink the LED without using delay(). It keeps track of the last time it turned the LED on or off. Then, each time through loop() it checks if a sufficient interval has passed - if it has, it turns the LED off if it was on and vice-versa.

Circuit

to:

Alguna vez puede ser necesario hacer parpadear un LED (o alguna otra cuestión visible) al mismo tiempo que se hacen otras cosas (como controlar la pulsación de un botón). Esto implica no poder utilizar delay(), o todo se pararía mientras el LED parpadea. Aquí tienes un código que muestra cómo hacer parpadear el LED sin usar delay(). Controla la última vez que se encendió o apagó el LED. Entonces, cada vez que pasa por el bucle() compara si ha transcurrido un intervalo suficiente de tiempo y si es así, apaga el LED si estaba encendido o viceversa.

Circuito

Changed lines 11-14 from:

Schematic:

click the image to enlarge

to:

Esquema:

haz click en la imagen para ampliarla

June 01, 2010, at 01:12 PM by Equipo Traduccion -
Changed lines 3-4 from:

parpadeo sin retardo ("delay")

to:

parpadeo sin retardo (delay)

June 01, 2010, at 01:11 PM by Equipo Traduccion -
Changed lines 1-4 from:

Examples > Digital I/O

Blink Without Delay

to:

Ejemplos > Digital E/S

parpadeo sin retardo ("delay")

Alguna vez puede ser necesario hacer parpadear un LED (o alguna otra cuestión visible) al mismo tiempo que se hacen otras cosas (como controlar la pulsación de un botón). Esto implica no poder utilizar delay()

June 01, 2010, at 01:03 PM by Equipo Traduccion -
Changed lines 18-19 from:

Code

div class=code
)
to:
February 09, 2010, at 04:51 AM by Tom Igoe -
February 09, 2010, at 04:50 AM by Tom Igoe -
Changed lines 19-79 from:
to:
July 05, 2009, at 07:12 PM by Tom Igoe -
Changed line 80 from:
to:
July 05, 2009, at 07:09 PM by Tom Igoe -
Changed lines 19-21 from:

[@ /* Blink without Delay

to:
Changed lines 41-43 from:
 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.
to:
 // constants won't change. Used here to 
 // set pin numbers:
 const int ledPin =  13;      // the number of the LED pin
Changed lines 45-48 from:
  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.
to:
 // Variables will change:
 int ledState = LOW;             // ledState used to set the LED
 long previousMillis = 0;        // will store last time LED was updated
Added lines 49-51:
 // the follow variables is a long because the time, measured in miliseconds,
 // will quickly become a bigger number than can be stored in an int.
 long interval = 1000;           // interval at which to blink (milliseconds)
Changed lines 53-56 from:
 created 2007
 by David A. Mellis
 modified 17 Jun 2009
 by Tom Igoe
to:
 void setup() {
   // set the digital pin as output:
   pinMode(ledPin, OUTPUT);      
 }
Added lines 58-60:
 void loop()
 {
   // here is where you'd put code that needs to be running all the time.
Changed lines 62-103 from:
 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used here to // set pin numbers: const int ledPin = 13; // the number of the LED pin

// Variables will change: int ledState = LOW; // ledState used to set the LED long previousMillis = 0; // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long interval = 1000; // interval at which to blink (milliseconds)

void setup() {

  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      

}

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, is the difference
  // between the current time and last time we blinked the LED bigger than
  // the interval at which we want to blink the LED.
  if (millis() - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = millis();   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }

} @]

to:
June 25, 2009, at 01:55 PM by Tom Igoe -
Added lines 7-17:

Circuit

Schematic:

click the image to enlarge

June 17, 2009, at 11:17 PM by Tom Igoe -
Changed lines 9-11 from:
 [=

int ledPin = 13; // LED connected to digital pin 13 int value = LOW; // previous value of the LED

to:

[@ /* 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 2007
 by David A. Mellis
 modified 17 Jun 2009
 by Tom Igoe

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

// constants won't change. Used here to // set pin numbers: const int ledPin = 13; // the number of the LED pin

// Variables will change: int ledState = LOW; // ledState used to set the LED

Added lines 38-40:

// the follow variables is a long because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int.

Changed lines 43-45 from:

void setup() {

  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
to:

void setup() {

  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
Changed lines 56-60 from:
    previousMillis = millis();   // remember the last time we blinked the LED

    // if the LED is off turn it on and vice-versa.
    if (value == LOW)
      value = HIGH;
to:
    // save the last time you blinked the LED 
    previousMillis = millis();   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
Changed line 63 from:
      value = LOW;
to:
      ledState = LOW;
Changed lines 65-66 from:
    digitalWrite(ledPin, value);
to:
    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
Changed line 69 from:
 =]
to:

@]

December 20, 2007, at 06:41 AM by David A. Mellis -
Changed lines 7-8 from:

Code

to:

Code

December 20, 2007, at 06:41 AM by David A. Mellis -
Changed lines 1-2 from:

Blinking an LED without using the delay() function.

to:

Examples > Digital I/O

Blink Without Delay

December 20, 2007, at 06:40 AM by David A. Mellis -
Deleted lines 7-18:

/* Blinking LED without using 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.
 *
 * Created 14 February 2006
 * David A. Mellis
 * http://arduino.berlios.de
 */
May 09, 2006, at 12:14 PM by David A. Mellis - int -> long
Deleted line 20:

int previousMillis = 0; // will store last time LED was updated

Changed lines 22-23 from:

int interval = 1000; // interval at which to blink (milliseconds)

to:

long previousMillis = 0; // will store last time LED was updated long interval = 1000; // interval at which to blink (milliseconds)

February 14, 2006, at 06:08 PM by 85.18.81.162 -
Added lines 1-49:

Blinking an LED without using the delay() function.

Sometimes you need to blink an LED (or some other time sensitive function) at the same time as something else (like watching for a button press). That means you can't use delay(), or you'd stop everything else the program while the LED blinked. Here's some code that demonstrates how to blink the LED without using delay(). It keeps track of the last time it turned the LED on or off. Then, each time through loop() it checks if a sufficient interval has passed - if it has, it turns the LED off if it was on and vice-versa.

Code

 
/* Blinking LED without using 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.
 *
 * Created 14 February 2006
 * David A. Mellis
 * http://arduino.berlios.de
 */

int ledPin = 13;                // LED connected to digital pin 13
int previousMillis = 0;         // will store last time LED was updated
int value = LOW;                // previous value of the LED
int interval = 1000;            // interval at which to blink (milliseconds)

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

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, is the difference
  // between the current time and last time we blinked the LED bigger than
  // the interval at which we want to blink the LED.
  if (millis() - previousMillis > interval) {
    previousMillis = millis();   // remember the last time we blinked the LED

    // if the LED is off turn it on and vice-versa.
    if (value == LOW)
      value = HIGH;
    else
      value = LOW;

    digitalWrite(ledPin, value);
  }
}
 

Share