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

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 2.2 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 * Use the onboard LED.
9 * Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
10  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
11  the correct LED pin independent of which board is used.
12  If you want to know what pin the on-board LED is connected to on your Arduino model, check
13  the Technical Specs of your board  at https://www.arduino.cc/en/Main/Products
14
15 created 2005
16 by David A. Mellis
17 modified 8 Feb 2010
18 by Paul Stoffregen
19 modified 11 Nov 2013
20 by Scott Fitzgerald
21 modified 9 Jan 2017
22 by Arturo Guadalupi
23
24
25 This example code is in the public domain.
26
27 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
28 */
29
30// constants won't change. Used here to set a pin number :
31const int ledPin =  LED_BUILTIN;// the number of the LED pin
32
33// Variables will change :
34int ledState = LOW;             // ledState used to set the LED
35
36// Generally, you should use "unsigned long" for variables that hold time
37// The value will quickly become too large for an int to store
38unsigned long previousMillis = 0;        // will store last time LED was updated
39
40// constants won't change :
41const long interval = 1000;           // interval at which to blink (milliseconds)
42
43void setup() {
44  // set the digital pin as output:
45  pinMode(ledPin, OUTPUT);
46}
47
48void loop() {
49  // here is where you'd put code that needs to be running all the time.
50
51  // check to see if it's time to blink the LED; that is, if the
52  // difference between the current time and last time you blinked
53  // the LED is bigger than the interval at which you want to
54  // blink the LED.
55  unsigned long currentMillis = millis();
56
57  if (currentMillis - previousMillis >= interval) {
58    // save the last time you blinked the LED
59    previousMillis = currentMillis;
60
61    // if the LED is off turn it on and vice-versa:
62    if (ledState == LOW) {
63      ledState = HIGH;
64    } else {
65      ledState = LOW;
66    }
67
68    // set the LED with the ledState of the variable:
69    digitalWrite(ledPin, ledState);
70  }
71}
72
Note: See TracBrowser for help on using the repository browser.