if i run this code as is the wave file plays, if i uncomment the IRdecode myDecoder wav file no long plays. would this be because of arduino uno's 16-bit timer library limitations. if so any way to fix it.
#include <IRLibAll.h>
#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"
TMRpcm tmrpcm;
IRrecv myReceiver(2);//receiver on pin 2
//IRdecode myDecoder;//Decoder object
//int ledPin = 8; // choose the pin for the LED
//int val = 1;
void setup(){
//pinMode(ledPin, OUTPUT);
//myReceiver.enableIRIn(); // Start the receiver
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(2);
tmrpcm.play("music");
}
void loop(){ }
I'm guessing this has something to do with it (see below)but have no idea how to fix it. I'm using an uno r3. i have an sd card using pins 10,11,12,13 ir sensor using pin 2, a speaker using pin 9 and an led using pin 8.
https://www.robotshop.com/letsmakerobots/arduino-101-timers-and-interrupts
PWM and timer
There is fixed relation between the timers and the PWM capable outputs. When you look in the data sheet or the pinout of the processor these PWM capable pins have names like OCRxA, OCRxB or OCRxC (where x means the timer number 0..5). The PWM functionality is often shared with other pin functionality.
The Arduino has 3Timers and 6 PWM output pins. The relation between timers and PWM outputs is:
Pins 5 and 6: controlled by timer0
Pins 9 and 10: controlled by timer1
Pins 11 and 3: controlled by timer2
Pitfalls
There exists some pitfalls you may encounter, when programming your Arduino and make use of functions or libraries that uses timers.
Servo Library uses Timer1. You can’t use PWM on Pin 9, 10 when you use the Servo Library on an Arduino. For Arduino Mega it is a bit more difficult. The timer needed depends on the number of servos. Each timer can handle 12 servos. For the first 12 servos timer 5 will be used (loosing PWM on Pin 44,45,46). For 24 Servos timer 5 and 1 will be used (loosing PWM on Pin 11,12,44,45,46).. For 36 servos timer 5, 1 and 3 will be used (loosing PWM on Pin 2,3,5,11,12,44,45,46).. For 48 servos all 16bit timers 5,1,3 and 4 will be used (loosing all PWM pins).
Pin 11 has shared functionality PWM and MOSI. MOSI is needed for the SPI interface, You can’t use PWM on Pin 11 and the SPI interface at the same time on Arduino. On the Arduino Mega the SPI pins are on different pins.
tone() function uses at least timer2. You can’t use PWM on Pin 3,11 when you use the tone() function an Arduino and Pin 9,10 on Arduino Mega.