noTone . This function has just one
argument, which is the pin on which the tone is playing.
Feeding Shift Registers Sometimes the Arduino Uno just doesn’t have enough pins. When driving a large number
of LEDs, for example, a common technique is to use a shift register chip. This chip reads
data one bit at a time, and then when it has enough, it latches all those bits onto a set of
outputs (one per bit).
To help you use this technique, there is a handy function called
shift-Out . This function
takes four arguments:
• The number of the pin on which the bit to be sent will appear.
• The number of the pin to be used as a clock pin. This toggles every time a bit is sent.
• A flag to determine whether the bits will be sent starting with the least significant bit or
the most significant. This should be one of the constants
MSBFIRST or
LSBFIRST .
• The byte of data to be sent.
Interrupts One of the things that tend to frustrate programmers used to “programming in the large” is
that the Arduino can do only one thing at a time. If you like to have lots of threads of
execution all running at the same time in your programs, then you are out of luck.
Although a few people have developed projects that can execute multiple threads in this
way, generally this capability is unnecessary for the type of uses that an Arduino is
normally put to. The closest an Arduino gets to such execution is the use of interrupts.
Two of the pins on the Arduino (D2 and D3) can have interrupts attached to them. That
is, these pins act as inputs that, if the pins receive a signal in a specified way, the
Arduino’s processor will suspend whatever it was doing and run a function attached to that
interrupt.
Sketch 7-04 blinks an LED, but then changes the blink period when an interrupt is
received. You can simulate an interrupt by connecting your wire between pin D2 and GND
and using the internal pull-up resistor to keep the interrupt high most of the time.