Hardware Reference
In-Depth Information
{
setLed(SS1, REG0, i);
setLed(SS1, REG1, i);
setLed(SS2, REG0, i);
setLed(SS2, REG1, i);
delay(10);
}
delay(300);
}
In Listing 9-1, SS for chip 1 is connected to pin 10, and SS for chip 2 is
connected to pin 9. You can cross reference this with the hardware connec-
tions that you made while wiring the system in the previous section. The
byte register values at the top of the file are the same binary sequences that
you determined from the datasheet earlier in this chapter. When you put a B
before a string of 0s and 1s when creating a byte variable, you are telling the
Arduino compiler that what follows is in binary format, and not the default
decimal format that you use elsewhere in your program. The setLed() func-
tion accepts an SS pin number, a register byte, and potentiometer level value.
This function uses the information to transmit the data to the appropriate
chip. In loop() , all the LEDs are ramped up, then back down again, with
short delays so that the transition does not occur so fast that you cannot see
it. When you load this onto your Arduino, you should observe all four lights
changing intensity in tandem as the potentiometers are all adjusted.
NOTE TowatchademovideooftheSPIdigitalpotentiometercoloradjuster,
visit www.exploringarduino.com/content/ch9 .Youcanalsofindthisvideo
ontheWileywebsiteshownatthebeginningofthischapter.
Now that you have this simple example working, you can move on to the
next section, where you increase the complexity of the system by turning it into
an audiovisual display.
CreatinganAudiovisualDisplayUsingSPIDigital
Potentiometers
Changing LED brightness is a good test to confirm your understanding of SPI
communication, but it is also something that you can do with PWM. Next, you
integrate some technology that you cannot replicate with a PWM interface:
sound. As you learned in Chapter 5, “Making Sounds,” the Arduino IDE has a
tone library that allows you to easily produce square waves from any pin on the
Arduino to drive a speaker. Although this allows you to easily create a range of
frequencies, it does not allow you to change the volume of the audio, because
that is a function of the waveform's amplitude. You have already learned how
 
Search WWH ::




Custom Search