{
flash(200); flash(200); flash(200); // S
delay(300); // delay to seperate flashes
flash(500); flash(500); flash(500); // O
delay(300); // delay to seperate flashes
flash(200); flash(200); flash(200); // S
delay(2000); // delay to reset SOS flash sequence
}
// END CODE
--
The code works just fine - but my question has to do with the term "duration" in the void flash(int duration) section - which I have highlighted in red.
The term "duration" in the delay(duration) does not seem to ever be defined. But if I try to change the term "duration" to something else (like "dur") I get an error in the compiler. Is "duration" a pre-determined command? If so, what does it do? I'm just not following the syntax of this sketch very well and could use some help parsing it out.
The function call includes a declaration of an integer called "duration." Anything that calls flash() much include an integer.
later in your code you use (note, I've put statement on its own line, as you should too):
phear_sc:
flash(200);
flash(200);
flash(200);
So you declared the function flash() with a variable called duration. Then in your loop() you call flash with a value of 200. This means inside of the function flash, the variable duration has a the value of 200.
Second, and please do forgive me, I'm still not following. I guess I still don't see where duration got defined in the flash statement (I realize this must look moronic to an experienced user).
digitalWrite(Pin12, HIGH); -- Power on Pin 12
delay(duration); delay for whatever number "duration" is defined as
digitalWrite(Pin12, LOW); -- Power off Pin 12
delay(duration); -- delay for whatever number "duration" is defined as
The way my mind is processing this code I would have to define "duration" at some point. I might say, for instance, int Duration = 50
Then, the delay in the above code would be 50 as it references back to my definition of Duration (i.e. 50) in the previous sentence.
Flash seems to be defined as the write/delay/write/delay code and I'm still just not seeing how adding a value to "flash" is populating "duration". Clearly I am not understanding Arduino's syntax correctly.
I guess I still don't see where duration got defined in the flash statement
void flash(int duration)
The highlighted bit is where you defined a variable. It gets its value when the function is called:
flash(200);
The highlighted bit becomes the value for duration.
You still need the parentheses in the function declaration, just like setup() and loop(). Otherwise, yes, that would use a constant, instead of a variable, for the on/off time.
I really appreciate both of you taking the time to answer my question so quickly. It can be so frustrating when you know the answer is something simple but you can't figure it out for want of someone more experienced just pointing at the obvious thing you're missing.