|
22 | 22 | by Scott Fitzgerald
|
23 | 23 | modified 9 Jan 2017
|
24 | 24 | by Arturo Guadalupi
|
| 25 | + modified 18 Feb 2018 |
| 26 | + by Alex Scott |
25 | 27 |
|
26 | 28 | This example code is in the public domain.
|
27 | 29 |
|
28 | 30 | http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
29 | 31 | */
|
30 | 32 |
|
31 |
| -// constants won't change. Used here to set a pin number: |
32 |
| -const int ledPin = LED_BUILTIN;// the number of the LED pin |
| 33 | +// Unchangeable constant to hold our blink interval in milliseconds: |
| 34 | +const long interval = 1000; |
33 | 35 |
|
34 |
| -// Variables will change: |
35 |
| -int ledState = LOW; // ledState used to set the LED |
| 36 | +// Setup a variable to hold our LED state |
| 37 | +int ledState = LOW; |
36 | 38 |
|
37 | 39 | // Generally, you should use "unsigned long" for variables that hold time
|
38 | 40 | // The value will quickly become too large for an int to store
|
39 | 41 | unsigned long previousMillis = 0; // will store last time LED was updated
|
40 | 42 |
|
41 |
| -// constants won't change: |
42 |
| -const long interval = 1000; // interval at which to blink (milliseconds) |
43 |
| - |
44 | 43 | void setup() {
|
45 |
| - // set the digital pin as output: |
46 |
| - pinMode(ledPin, OUTPUT); |
| 44 | + // Set the digital pin as output: |
| 45 | + pinMode(LED_BUILTIN, OUTPUT); |
47 | 46 | }
|
48 | 47 |
|
49 | 48 | void loop() {
|
50 |
| - // here is where you'd put code that needs to be running all the time. |
| 49 | + // This is where you'd put code that needs to be running all the time. |
51 | 50 |
|
52 |
| - // check to see if it's time to blink the LED; that is, if the difference |
53 |
| - // between the current time and last time you blinked the LED is bigger than |
| 51 | + // Check to see if it's time to blink the LED; that is, if the difference |
| 52 | + // between the current time and last time you blinked the LED is greater than |
54 | 53 | // the interval at which you want to blink the LED.
|
55 | 54 | unsigned long currentMillis = millis();
|
56 | 55 |
|
57 | 56 | if (currentMillis - previousMillis >= interval) {
|
58 |
| - // save the last time you blinked the LED |
| 57 | + // Save the last time you blinked the LED |
59 | 58 | previousMillis = currentMillis;
|
60 | 59 |
|
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 |
| - } |
| 60 | + // Inverse the state of our LED pin: |
| 61 | + ledState = !ledState; |
67 | 62 |
|
68 |
| - // set the LED with the ledState of the variable: |
69 |
| - digitalWrite(ledPin, ledState); |
| 63 | + // Set the LED with the updated LED state: |
| 64 | + digitalWrite(LED_BUILTIN, ledState); |
70 | 65 | }
|
71 | 66 | }
|
0 commit comments