All
I have tested the code below individually for IR read and SD card read and together alone they work. However having combined the code and compiled ok it doesn't appear to work.
The SD card is initiating ok and on start I hear a sound.
However I don't believe the IR sensor is readying any longer. I left in a serial print code to show on the serial monitor what was being received but now when checking all I see are zeros.... I go back and test the code separately and it all works ok ..... so I assume my circuit design is not the problem.
So at this stage I suspect its a conflict created one combining my two circuits and which is affecting IR sensor data...
Your thoughts / feedback would be much welcome;
// Title: IR Reader and Action Trigger (inc Sound Files on SD Card) + TBC
// Date: 26 May'15
// Notes: Compiled ok on 26May after adding prefix 0X and suffix ul for Hex code
// moved Serial.println(results.value, HEX) and irrecv.resume(); outside of button select of loop
/////////////////////////////////////////////////////////////////////////////////
// IRremote Libraries
#include <IRremote.h>
#include <IRremoteInt.h>
int RECV_PIN = 10; // using digital pin 10 on Uno for IR Rx. Chgd from 11 to 10 as conflict'd with SDcard MOSI pin
IRrecv irrecv(RECV_PIN);
decode_results results;
// SD Card Libraries
#include <SPI.h>
#include <SD.h>
#define SD_ChipSelectPin 4 // using digital pin 4 on arduino nano 328 for SD card select (CS)
#include <TMRpcm.h> // also need to include this library...
TMRpcm tmrpcm; // create an object for use in this sketch
char mychar;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
tmrpcm.speakerPin = 9; // using digital pin 9 on Uno, Nano (11 on Mega) for Spkr output
if (!SD.begin(SD_ChipSelectPin)) // see if the card is present and can be initialized:
{
Serial.println("SD fail");
return; // don't do anything more if not
}
tmrpcm.play("start.wav"); // Sound file "Start" will play each time arduino powers up, or is reset
}
void loop()
{
// put your main code here, to run repeatedly:
if (irrecv.decode(&results))
{
if(results.value == 0x9716BE3Ful) // Check IR input for hex 9716BE3F(for button1)to start playback
{
tmrpcm.play("button1.wav"); // Play sound file Button1 (???????)
}
else if(results.value == 0x3D9AE3F7ul) // Check IR input for hex 3D9AE3F7(for button2)to start playback
{
tmrpcm.play("button2.wav"); // Play sound file Button2 (???????)
}
}
Serial.println(results.value, HEX); // Send the Hex over the serial monitor (can remove later)
irrecv.resume(); // Receive the next value
}