Programming Arduino Getting Started with Sketches


Flasher:: . This indicates that the methods belong to the  Flasher



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə74/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   70   71   72   73   74   75   76   77   78
Arduino SimonMonk 2011

Flasher::
. This indicates that the methods belong to the 
Flasher
class.
The constructor method (
Flasher
) just assigns each of its parameters to the appropriate
private member variable. The 
duration
parameter is divided by two before being assigned
to the member variable 
_d
. This is because the delay is called twice, and it seems more
logical for the duration to be the total duration of the flash and the gap between flashes.
The 
flash
function actually carries out the business of flashing; it loops for the
appropriate number of times, turning the LED on and off for the appropriate delay.
Completing Your Library
You have now seen all of the essentials for completing the library. You could now deploy
this library and it would work just fine. However, there are two further steps that you
should take to complete your library. One is to define the keywords used in the library so


that the Arduino IDE can show them in the appropriate color when users are editing code.
The other is to include some examples of how to use the library.
Keywords
To define the keywords, you have to create a file called keywords.txt, which goes into the
Flasher directory. This file contains just the two following lines:
This is essentially a two-column table in a text file. The left column is the keyword and
the right column an indication of the type of keyword it is. Class names should be a
KEYWORD1
and methods should be 
KEYWORD2
. It does not matter how many spaces
or tabs you put between the columns, but each keyword should start on a new line.
Examples
The other thing that you, as a good Arduino citizen, should include as part of the library is
a folder of examples. In this case, the library is so simple that a single example will
suffice.
The examples must all be placed in a folder called examples inside the Flasher folder.
The example is in fact just an Arduino sketch, so you can create the example using the
Arduino IDE. But first, you have to quit and then reopen the Arduino IDE to make it
aware of the new library.
After restarting the Arduino IDE, from the Arduino IDE’s menu, select File and then
New to create a new sketch window. Then from the Menu, select Sketch and the Import
Library option. The Options should look something like 
Figure 11-1
.
The libraries above the line in the submenu are the official libraries; below this line are
the “unofficial” contributed libraries. If all has gone well, you should see Flasher in the
list.
If Flasher is not in the list, it is very likely that the Flasher folder is not in the libraries
folder of your sketches folder, so go back and check.


Figure 11-1
Importing the Flasher library
Type the flowing into the sketch window that has just been created:


The Arduino IDE will not allow you to save the example sketch directly into the
libraries folder, so save it somewhere else under the name Simple Flasher Example and
then move the whole Simple Flasher Example folder that you just saved into the examples
folder in your library.
If you restart your Arduino IDE, you should now see that you are able to open the
example sketch from the menu as shown in 
Figure 11-2
.

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   70   71   72   73   74   75   76   77   78




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin