source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 1.9 KB
Line 
1/* Blink without Delay
2
3 Turns on and off a light emitting diode (LED) connected to a digital
4 pin, without using the delay() function.  This means that other code
5 can run at the same time without being interrupted by the LED code.
6
7 The circuit:
8 * LED attached from pin 13 to ground.
9 * Note: on most Arduinos, there is already an LED on the board
10 that's attached to pin 13, so no hardware is needed for this example.
11
12 created 2005
13 by David A. Mellis
14 modified 8 Feb 2010
15 by Paul Stoffregen
16 modified 11 Nov 2013
17 by Scott Fitzgerald
18
19
20 This example code is in the public domain.
21
22 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
23 */
24
25// constants won't change. Used here to set a pin number :
26const int ledPin =  13;      // the number of the LED pin
27
28// Variables will change :
29int ledState = LOW;             // ledState used to set the LED
30
31// Generally, you should use "unsigned long" for variables that hold time
32// The value will quickly become too large for an int to store
33unsigned long previousMillis = 0;        // will store last time LED was updated
34
35// constants won't change :
36const long interval = 1000;           // interval at which to blink (milliseconds)
37
38void setup() {
39  // set the digital pin as output:
40  pinMode(ledPin, OUTPUT);
41}
42
43void loop() {
44  // here is where you'd put code that needs to be running all the time.
45
46  // check to see if it's time to blink the LED; that is, if the
47  // difference between the current time and last time you blinked
48  // the LED is bigger than the interval at which you want to
49  // blink the LED.
50  unsigned long currentMillis = millis();
51
52  if (currentMillis - previousMillis >= interval) {
53    // save the last time you blinked the LED
54    previousMillis = currentMillis;
55
56    // if the LED is off turn it on and vice-versa:
57    if (ledState == LOW) {
58      ledState = HIGH;
59    } else {
60      ledState = LOW;
61    }
62
63    // set the LED with the ledState of the variable:
64    digitalWrite(ledPin, ledState);
65  }
66}
67
Note: See TracBrowser for help on using the repository browser.