Use SD Card while Pin 11 is being used for PWM On Arduino Uno Rev3, I just ran the speaker_pcm demo that used TIMER1 and TIMER2 to generate a PWM wave. However, this means that the Pins 3, 9, 10 and 11 can not be used anymore; according to the documentation:

Takes over Timer 1 (16-bit) for the 8000 Hz timer. This breaks PWM
(analogWrite()) for Arduino pins 9 and 10. Takes Timer 2 (8-bit)
for the pulse width modulation, breaking PWM for pins 11 &amp; 3.


I wanted to change the program such that the WAV data was read from a SD card. However, this is what documentation for SD.h library says:

The communication between the microcontroller and the SD card uses SPI,
which takes place on digital pins 11, 12, and 13 (on most Arduino boards)


This means both the SD.h and speaker_pcm want to use pin 11, and the requirement to use these pins is dictated by the hardware. I am guessing that this clash will create problems.

Is there any way I can make this work? Can I switch between SD card reading and Audio playing somehow (essentially multiplexing in software)? Or will this collision of pin usage not be a problem?
The program you link to does not take over pins 3, 9, 10 and 11, it
takes over Timer 1 and Timer 2, which are used to provide PWM capability
on those pins. This means you cannot do analogWrite() on those pins
anymore, but you still can use them for other purposes, including SPI
access to an SD card.

Note, however, this line of code:

int speakerPin = 11; // Can be either 3 or 11, two PWM outputs connected to Timer 2


This of course will conflict the SPI port using pin 11 as MOSI. You can
fix this conflict simply by setting speakerPin to 3 instead of 11.