Skip to content

Commit a514de4

Browse files
jasonacoxper1234
andauthored
Add explanation for basis of begin() function
Co-authored-by: per1234 <accounts@perglass.com>
1 parent 2b8ed08 commit a514de4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

content/learn/08.contributions/03.arduino-creating-library-guide/arduino-creating-library-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Morse::Morse(int pin)
138138

139139
There are a couple of strange things in this code. First is the **Morse::** before the name of the function. This says that the function is part of the **Morse** class. You'll see this again in the other functions in the class. The second unusual thing is the underscore in the name of our private variable, `_pin`. This variable can actually have any name you want, as long as it matches the definition in the header file. Adding an underscore to the start of the name is a common convention to make it clear which variables are private, and also to distinguish the name from that of the argument to the function (**pin** in this case).
140140

141-
Next, you'll create a `begin()` function that will be called in `setup()`, after the hardware has been initialized by the Arduino main function. In our example, we need to set the pin as an output:
141+
Next, you'll create a `begin()` function to handle hardware configuration. This will be called from the `setup()` function of the sketch. Hardware configuration is done in a dedicated function instead of the constructor because the hardware has not yet been initialized at the time the constructor code is executed. In our library, we need to set the pin as an output:
142142

143143
```arduino
144144
void Morse::begin()

0 commit comments

Comments
 (0)