Hint taken. ![]()
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SFEMP3Shield MP3player;
//new ir code
int irPin = A0; //Sensor pin 1 wired to Arduino's pin 2
int statLED = 13; //Toggle the status LED every time Power is pressed
int start_bit = 2200; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)
void setup() {
 pinMode(irPin, INPUT);
   // turn on the MP3 chip
  MP3player.begin();
}
void loop() {
 int key = getIRKey();Â
 if (key !=0) // bingo! bring on the noise! bring on the funk!
 Â
    // start playing the sound
 switch(key)
  }
{
 case 144: MP3player.playTrack(1); break;
 case 145: MP3player.playTrack(2); break;
 case 146: MP3player.playTrack(3); break;
 case 147: MP3player.playTrack(4); break;
}
int getIRKey() {
 int data[12];
 int i;
 while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit
Â
 for(i = 0 ; i < 11 ; i++)
  data[i] = pulseIn(irPin, LOW); //Start measuring bits, I only want low pulses
Â
 for(i = 0 ; i < 11 ; i++) //Parse them
 {  Â
  if(data[i] > bin_1) //is it a 1?
   data[i] = 1;
  else if(data[i] > bin_0) //is it a 0?
   data[i] = 0;
  else
   return -1; //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
 }
 int result = 0;
 for(i = 0 ; i < 11 ; i++) //Convert data bits to integer
  if(data[i] == 1) result |= (1<<i);
 return result; //Return key number
}