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):
int x = 0b10;
bitWrite(x, 0, 1);
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.
Figure 7.3 A square-wave signal .
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