8
8
* LED attached from pin 13 to ground.
9
9
* Note: on most Arduinos, there is already an LED on the board
10
10
that's attached to pin 13, so no hardware is needed for this example.
11
-
12
-
11
+
13
12
created 2005
14
13
by David A. Mellis
15
14
modified 8 Feb 2010
16
15
by Paul Stoffregen
17
-
16
+ modified 11 Nov 2013
17
+ by Scott Fitzgerald
18
+
19
+
18
20
This example code is in the public domain.
19
-
20
-
21
+
21
22
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
22
23
*/
23
24
24
- // constants won't change. Used here to
25
- // set pin numbers:
25
+ // constants won't change. Used here to set a pin number :
26
26
const int ledPin = 13 ; // the number of the LED pin
27
27
28
- // Variables will change:
28
+ // Variables will change :
29
29
int ledState = LOW; // ledState used to set the LED
30
- long previousMillis = 0 ; // will store last time LED was updated
31
30
32
- // the follow variables is a long because the time, measured in miliseconds,
33
- // will quickly become a bigger number than can be stored in an int.
34
- long interval = 1000 ; // interval at which to blink (milliseconds)
31
+ // Generally, you shuould use "unsigned long" for variables that hold time
32
+ // The value will quickly become too large for an int to store
33
+ unsigned long previousMillis = 0 ; // will store last time LED was updated
34
+
35
+ // constants won't change :
36
+ const long interval = 1000 ; // interval at which to blink (milliseconds)
35
37
36
38
void setup () {
37
39
// set the digital pin as output:
@@ -47,10 +49,10 @@ void loop()
47
49
// the LED is bigger than the interval at which you want to
48
50
// blink the LED.
49
51
unsigned long currentMillis = millis ();
50
-
51
- if (currentMillis - previousMillis > interval) {
52
- // save the last time you blinked the LED
53
- previousMillis = currentMillis;
52
+
53
+ if (currentMillis - previousMillis >= interval) {
54
+ // save the last time you blinked the LED
55
+ previousMillis = currentMillis;
54
56
55
57
// if the LED is off turn it on and vice-versa:
56
58
if (ledState == LOW)
0 commit comments