After changing again three times in a row 13 to whatever i need to blink as a test, I thought it would be a good idea to have the blink demo use variables for the pin and blink tempo. below my suggestion for a new version of the sketch:
/*
int ledPin = 13;
int blinkTime = 1000;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(ledPin, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(blinkTime); // wait for a blinkTime milliseconds
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(blinkTime); // wait for a blinkTime milliseconds
}
Oops sorry, wrong paste. here the full code. what do you mean with code tags?
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the Uno and
Leonardo, it is attached to digital pin 13. If you're unsure what
pin the on-board LED is connected to on your Arduino model, check
the documentation at http://arduino.cc
This example code is in the public domain.
modified
20140508 by Scott Fitzgerald
20150619 by Simon Claessen
*/
int ledPin = 13;
int blinkTime = 1000;
void setup() {
pinMode(ledPin, OUTPUT); // initialize ledPin as an output.
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(ledPin, HIGH); // turn ledPin on (HIGH is the voltage level)
delay(blinkTime); // wait for a blinkTime milliseconds
digitalWrite(ledPin, LOW); // turn ledPin off by making the voltage LOW
delay(blinkTime); // wait for a blinkTime milliseconds
}
The Arduino team seem to be going for simplicity. If you take a look at this difference file, you'll see that the pin number was once a variable, but was removed in favor of directly writing the pin number.
He is talking about the the time variable should be added, keeping the pin number same. Right?
We can add a time variable then leave everything else same.
But why add more complexity to a code intended for a beginner? The code is enough.
If someone needs a variable he can modify the rest of the code of his own.
No, no need. Leave it as it is. Making things complicated is not our philosophy. After all Arduino is meant for all, a starter and for a pro also. Let people make their code advance.