Programming Arduino Getting Started with Sketches


Flasher object to use in a sketch. For example, you could put the following in a sketch: This would create a new  Flasher



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

Flasher
object to use in a
sketch.
For example, you could put the following in a sketch:
This would create a new 
Flasher
called 
slowFlasher
that would flash on pin D13 with a
duration of 500 milliseconds.
The second method in the class is called 
flash
. This method takes a single argument of
the number of times to flash. Because it is associated with a class, when you want to call
it, you have to refer to the object that you created earlier, as follows:
This would cause the LED to flash ten times at the period that you specified in the
constructor to the 
Flasher
object.
The private section of the class contains two variable definitions: one for the pin, and
one for the duration, which is simply called 
d
. Every time that you create an object of
class 
Flasher
, it will have these two variables. This enables it to remember the pin and
duration when a new 
Flasher
object is created.
These variables are called member variables because they are members of the class.
Their names generally are unusual in that they start with an underscore character;


however, this is just a common convention, not a programming necessity. Another
commonly used naming convention is to use a lowercase 
m
(for 
member
) as the first letter
of the variable name.
The Implementation File
The header file has just defined what the class looks like. You now need a separate file
that actually does the work. This is called the implementation file and has the extension
.cpp.
So, create a new file containing the following and save it as Flasher.cpp in the Flasher
folder:
There is some unfamiliar syntax in this file. The method names are both prefixed by

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