I was wondering what would be a better way to code two leds in parallel that act like a second counter for an alarm clock I am building?
Example A
const int ledBlinker = 12;
void setup(){
pinMode (ledBlinker, OUTPUT);
}
void loop() {
/*This is my code for blinking two LEDs in parallel.
I am trying to simulate the seconds blinking of a
standard digital alarm clock. */
digitalWrite(ledBlinker, HIGH);
delay(1000);
digitalWrite(ledBlinker, LOW);
delay(1000);
}
Or is this a more appropriate way to do it by creating a function?
Example B:
const int ledBlinker = 12;
const int delayPeriod = 1000;
void setup(){
pinMode (ledBlinker, OUTPUT);
}
void loop() {
blinker();
}
/*This is my code for blinking two LEDs in parallel.
I am trying to simulate the seconds blinking of a
standard digital alarm clock. */
void blinker()
{
digitalWrite(ledBlinker, HIGH);
delay(delayPeriod);
digitalWrite(ledBlinker, LOW);
delay(delayPeriod);
}
What is the benefit of writing it one way or the other? Thanks for the help.