Skip to content

Commit c58484c

Browse files
codetheoristper1234
authored andcommitted
Update BlinkWithoutDelay.ino example
* Remove unused ledPin constant * Make comments more natural language * Change if/ese statement to demonstrate shorthand variable flipping
1 parent b3da224 commit c58484c

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,45 @@
2222
by Scott Fitzgerald
2323
modified 9 Jan 2017
2424
by Arturo Guadalupi
25+
modified 18 Feb 2018
26+
by Alex Scott
2527
2628
This example code is in the public domain.
2729
2830
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
2931
*/
3032

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;
3335

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;
3638

3739
// Generally, you should use "unsigned long" for variables that hold time
3840
// The value will quickly become too large for an int to store
3941
unsigned long previousMillis = 0; // will store last time LED was updated
4042

41-
// constants won't change:
42-
const long interval = 1000; // interval at which to blink (milliseconds)
43-
4443
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);
4746
}
4847

4948
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.
5150

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
5453
// the interval at which you want to blink the LED.
5554
unsigned long currentMillis = millis();
5655

5756
if (currentMillis - previousMillis >= interval) {
58-
// save the last time you blinked the LED
57+
// Save the last time you blinked the LED
5958
previousMillis = currentMillis;
6059

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;
6762

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);
7065
}
7166
}

0 commit comments

Comments
 (0)