Programming Arduino Getting Started with Sketches


int individually. The function  bitRead



Yüklə 5,42 Kb.
Pdf görüntüsü
səhifə56/78
tarix22.12.2023
ölçüsü5,42 Kb.
#189286
1   ...   52   53   54   55   56   57   58   59   ...   78
Arduino SimonMonk 2011

int
individually. The function 
bitRead
returns the value of a particular bit in
an 
int
; so, for the following example would assign the value 0 to the variable called 
bit
:
In the second argument, the bit position starts at 0 and goes up to 15. It starts with the least
significant bit. So the rightmost bit is bit 0, the next bit to the left is bit 1, and so on.
As you would expect, the counterpart to 
bitRead
is 
bitWrite
, which takes three
arguments. The first is the number to manipulate, the second is the bit position, and the
third is the bit value. The following example changes the value of the 
int
from 2 to 3 (in
decimal or hex):


Figure 7-2
An
int
Advanced I/O
There are some useful little functions that you can use to make your life easier when
performing various input/output tasks.
Generating Tones
The 
tone
function allows you to generate a square-wave signal (see 
Figure 7-3
) on one of
the digital output pins. The most common reason to do this is to generate an audible tone
using a loudspeaker or buzzer.
The function takes either two or three arguments. The first argument is always the pin
number on which the tone is to be generated, the second argument is the frequency of the
tone in hertz (Hz), and the optional final argument is the duration of the tone. If no
duration is specified, then the tone will continue playing indefinitely, as is the case in
sketch 7-03. This is why we have put the 
tone
function call in 
setup
rather than in the
loop
function.
Figure 7-3
A square-wave signal


To stop a tone that is playing, you use the function 

Yüklə 5,42 Kb.

Dostları ilə paylaş:
1   ...   52   53   54   55   56   57   58   59   ...   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