Pages: [1]   Go Down
Author Topic: Audio not playing within new code.  (Read 1504 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all,

I've been working on an LED cloud project I first found on instructables and have been modifying it to play a few audio clips.
Here is the problem I'm having...

I know the audio is working because the  .WAV clips will play if I simply send character commands through the serial monitor.
The IR reciever also works properly and turns on the correct sequence of LEDs.
But the  .WAV files will not play in my project code and I'm not sure why.
I'm using this wav library I got from Github.  https://github.com/TMRh20/TMRpcm
And this is how I have my speaker hardware setup. http://bryanduxbury.files.wordpress.com/2012/01/amplified2.png
The only difference with this is I am not using a resistor and the power source for the speaker is external.

Any help you guys could provide would be greatly appreciated. smiley-grin
My code is posted below.

Code:
#include <IRremote.h>
#include <SD.h>
#include <TMRpcm.h>

#define SD_ChipSelectPin 10
#define powercode 0xA10CA00F
#define stormcode 0xA10C4C03 

int RECV_PIN = 8;
int yellow = 0;
int red = 1;
int red2 = 2;
int yellow2 = 3;
int blue = 4;
int purple = 5;
int purple2 = 6;
int white = 7;
long randOn;

IRrecv irrecv(RECV_PIN);
decode_results results;
TMRpcm tmrpcm;

void setup(){
 
  tmrpcm.speakerPin = 9;
  Serial.begin(9600);
  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
  }
  pinMode(red, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(yellow2, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(purple, OUTPUT);
  pinMode(white, OUTPUT);
  pinMode(purple2, OUTPUT);           
  irrecv.enableIRIn(); // Start the receiver
}


int redbool = 0;
int orangebool = 0;
int yellowbool = 0;
int greenbool = 0;
int bluebool = 0;
int purplebool = 0;
int whitebool = 0;
int rgbbool = 0;
int rainbowbool = 0;
int sunbool = 0;
int rainbool = 0;
int stormbool = 0;
int powerbool = 1;
int lightningLoop = 1;

unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results)) {
   
                 
//Sun

    if (results.value == 2464125561) {
      if (millis() - last > 250) {
        sunbool = !sunbool;
        if (sunbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
         
          digitalWrite (white, HIGH);
          digitalWrite (yellow, HIGH);
          digitalWrite (yellow2, HIGH);
          tmrpcm.play("birds.wav");
          }
      }
      last = millis();
    }
   
 //rain

    if (results.value == 2278412527) {
      if (millis() - last > 250) {
        rainbool = !rainbool;
        if (rainbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);

          tmrpcm.play("balls.wav");
          digitalWrite (white, HIGH);
          digitalWrite (blue, HIGH);
          }
      }
      last = millis();
    }   
//storm

    if (results.value == 930645859) {
      if (millis() - last > 250) {
        stormbool = !stormbool;
        if (stormbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (blue, HIGH);
          digitalWrite (purple, HIGH);
          digitalWrite (purple2, HIGH);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (white, LOW);

          tmrpcm.play("thunder.wav");
          digitalWrite (blue, HIGH);
          digitalWrite (purple, HIGH);
          digitalWrite (purple2, HIGH);
              randOn = random (10, 200);
              //Lightning Below
                 digitalWrite(white, HIGH);
                 delay(randOn); 
                 digitalWrite(white, LOW);
                 delay(randOn); 
                 digitalWrite(white, HIGH);
                 delay(randOn + randOn);   
                 digitalWrite(white, LOW);
               }
               }
      last = millis();
    }
 //rainbow
        if (results.value == 2769913147) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        rainbowbool = !rainbowbool;
        tmrpcm.play("rainbow.wav");
        digitalWrite(white, LOW);
        digitalWrite(red, rainbowbool ? HIGH : LOW);
        digitalWrite(red2, rainbowbool ? HIGH : LOW);
        digitalWrite(yellow, rainbowbool ? HIGH : LOW);
        digitalWrite(yellow2, rainbowbool ? HIGH : LOW);
        digitalWrite(blue, rainbowbool ? HIGH : LOW);
        digitalWrite(purple, rainbowbool ? HIGH : LOW);
        digitalWrite(purple2, rainbowbool ? HIGH : LOW);
      }
      last = millis();
    }   
   
 //red
        if (results.value == 1558024125) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        redbool = !redbool;
        digitalWrite(red, redbool ? HIGH : LOW);
        digitalWrite(red2, redbool ? HIGH : LOW);
      }
      last = millis();
    }
//orange
    if (results.value == 4382025) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        orangebool = !orangebool;
        digitalWrite(red, orangebool ? HIGH : LOW);
        digitalWrite(red2, orangebool ? HIGH : LOW);
        digitalWrite(yellow, orangebool ? HIGH : LOW);
        digitalWrite(yellow2, orangebool ? HIGH : LOW);
      }
      last = millis();
    }
//yellow
    if (results.value == 834338975) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        yellowbool = !yellowbool;
        digitalWrite(yellow, yellowbool ? HIGH : LOW);
        digitalWrite(yellow2, yellowbool ? HIGH : LOW);
      }
      last = millis();
    }
//green
    /*if (results.value == 356487335) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        greenbool = !greenbool;
        digitalWrite(green, greenbool ? HIGH : LOW);
        digitalWrite(green2, greenbool ? HIGH : LOW);
      }
      last = millis();
    }*/
//blue
    if (results.value == 1752348172) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        bluebool = !bluebool;
        digitalWrite(blue, bluebool ? HIGH : LOW);
      }
      last = millis();
    }
//purple
    if (results.value == 1851193636) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        purplebool = !purplebool;
        digitalWrite(purple, purplebool ? HIGH : LOW);
        digitalWrite(purple2, purplebool ? HIGH : LOW);
      }
      last = millis();
    }
//white
    /*if (results.value == 1181142029) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        whitebool = !whitebool;
        digitalWrite(white, whitebool ? HIGH : LOW);
        digitalWrite(white2, whitebool ? HIGH : LOW);
      }
      last = millis();
    }*/
    irrecv.resume();
  }
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have a conflict between Serial.begin(9600) which uses pins 0 and 1 for serial I/O and:
Code:
int yellow = 0;
int red = 1;

  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);

If you want to use Serial you can't use Pin 0 and Pin 1 for anything else.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@ johnwasser
Thanks John that makes sense. I've made the change but it doesn't solve the problem. The audio clips still refuse to play. When the IR codes are received, the arduino will turn on the proper LED sequence but it doesn't seem to want to execute the code "tmrpcm.play"

Code:
#include <IRremote.h>
#include <SD.h>
#include <TMRpcm.h>

#define SD_ChipSelectPin 10
#define powercode 0xA10CA00F
#define stormcode 0xA10C4C03 

int RECV_PIN = 8;
int yellow = 0;
int red = 1;
int red2 = 2;
int yellow2 = 3;
int blue = 4;
int purple = 5;
int purple2 = 6;
int white = 7;
long randOn;

IRrecv irrecv(RECV_PIN);
decode_results results;
TMRpcm tmrpcm;

void setup(){
 
  tmrpcm.speakerPin = 9;
 
  pinMode(red, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(yellow2, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(purple, OUTPUT);
  pinMode(white, OUTPUT);
  pinMode(purple2, OUTPUT);           
  irrecv.enableIRIn(); // Start the receiver
}

int redbool = 0;
int orangebool = 0;
int yellowbool = 0;
int greenbool = 0;
int bluebool = 0;
int purplebool = 0;
int whitebool = 0;
int rgbbool = 0;
int rainbowbool = 0;
int sunbool = 0;
int rainbool = 0;
int stormbool = 0;
int powerbool = 1;
int lightningLoop = 1;

unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results)) {
                   
//Sun

    if (results.value == 2464125561) {
      if (millis() - last > 250) {
        sunbool = !sunbool;
        if (sunbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
         
          digitalWrite (white, HIGH);
          digitalWrite (yellow, HIGH);
          digitalWrite (yellow2, HIGH);
          tmrpcm.play("birds.wav");
          }
      }
      last = millis();
    }
   
 //rain

    if (results.value == 2278412527) {
      if (millis() - last > 250) {
        rainbool = !rainbool;
        if (rainbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);

          tmrpcm.play("balls.wav");
          digitalWrite (white, HIGH);
          digitalWrite (blue, HIGH);
          }
      }
      last = millis();
    }
   
//storm

    if (results.value == 930645859) {
      if (millis() - last > 250) {
        stormbool = !stormbool;
        if (stormbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (blue, HIGH);
          digitalWrite (purple, HIGH);
          digitalWrite (purple2, HIGH);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (white, LOW);

          digitalWrite (blue, HIGH);
          digitalWrite (purple, HIGH);
          digitalWrite (purple2, HIGH);
          tmrpcm.play("thunder.wav");
              randOn = random (10, 200);
              //Lightning Below
                 digitalWrite(white, HIGH);
                 delay(randOn); 
                 digitalWrite(white, LOW);
                 delay(randOn); 
                 digitalWrite(white, HIGH);
                 delay(randOn + randOn);   
                 digitalWrite(white, LOW);
               }
               }
      last = millis();
    }
 //rainbow
 
        if (results.value == 2769913147) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        rainbowbool = !rainbowbool;
       
        digitalWrite(white, LOW);
        digitalWrite(red, rainbowbool ? HIGH : LOW);
        digitalWrite(red2, rainbowbool ? HIGH : LOW);
        digitalWrite(yellow, rainbowbool ? HIGH : LOW);
        digitalWrite(yellow2, rainbowbool ? HIGH : LOW);
        digitalWrite(blue, rainbowbool ? HIGH : LOW);
        digitalWrite(purple, rainbowbool ? HIGH : LOW);
        digitalWrite(purple2, rainbowbool ? HIGH : LOW);
        tmrpcm.play("rainbow.wav");
      }
      last = millis();
    }   
   
 //red
 
        if (results.value == 1558024125) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        redbool = !redbool;
        digitalWrite(red, redbool ? HIGH : LOW);
        digitalWrite(red2, redbool ? HIGH : LOW);
      }
      last = millis();
    }
   
//orange

    if (results.value == 4382025) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        orangebool = !orangebool;
        digitalWrite(red, orangebool ? HIGH : LOW);
        digitalWrite(red2, orangebool ? HIGH : LOW);
        digitalWrite(yellow, orangebool ? HIGH : LOW);
        digitalWrite(yellow2, orangebool ? HIGH : LOW);
      }
      last = millis();
    }
   
//yellow

    if (results.value == 834338975) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        yellowbool = !yellowbool;
        digitalWrite(yellow, yellowbool ? HIGH : LOW);
        digitalWrite(yellow2, yellowbool ? HIGH : LOW);
      }
      last = millis();
    }
   
//green

    /*if (results.value == 356487335) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        greenbool = !greenbool;
        digitalWrite(green, greenbool ? HIGH : LOW);
        digitalWrite(green2, greenbool ? HIGH : LOW);
      }
      last = millis();
    }*/
   
//blue

    if (results.value == 1752348172) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        bluebool = !bluebool;
        digitalWrite(blue, bluebool ? HIGH : LOW);
      }
      last = millis();
    }
   
//purple

    if (results.value == 1851193636) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        purplebool = !purplebool;
        digitalWrite(purple, purplebool ? HIGH : LOW);
        digitalWrite(purple2, purplebool ? HIGH : LOW);
      }
      last = millis();
    }
   
//white

    /*if (results.value == 1181142029) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        whitebool = !whitebool;
        digitalWrite(white, whitebool ? HIGH : LOW);
        digitalWrite(white2, whitebool ? HIGH : LOW);
      }
      last = millis();
    }*/
    irrecv.resume();
  }
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The 'basic' TMRpcm example has some setup code for the SD card which you don't have in your sketch.  This is needed to tell the SD library which pin is connected to the SD card's Chip Select pin.  What pin are you using for the SD card?  If it's 4 you can't also use that for the Blue LED.

Code:
#include <SD.h>                      // need to include the SD library
//#define SD_ChipSelectPin 53  //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>           //  also need to include this library...

TMRpcm tmrpcm;   // create an object for use in this sketch

void setup(){
  tmrpcm.speakerPin = 9;  //5, 6, 11 or 46 on Mega, 9 on Uno, Nano, etc

  Serial.begin(9600);

  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("music"); //the sound file "music" will play each time the arduino powers up, or is reset
}

void loop() { 
  if(Serial.available()) {   
    if(Serial.read() == 'p') {
      //send the letter p over the serial monitor to start playback
      tmrpcm.play("music");
    }
  }
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@johnwasser

I'm using pin 10 as the chip select line. Is this causing a problem within the library?
I don't have any LEDs using pin 10.

#define SD_ChipSelectPin 10
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@johnwasser

I'm using pin 10 as the chip select line. Is this causing a problem within the library?
I don't have any LEDs using pin 10.

#define SD_ChipSelectPin 10

That line doesn't help if you don't put SD.begin(SD_ChipSelectPin) in setup().
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmmm its still giving me some trouble.  smiley-confuse No audio yet. It seems like the code is fine but the program will not "pause" and play   tmrpcm.play("birds.wav"); or any of the others because it only plays the first millisecond or so. Is this a valid hypothesis or am I crazy?

Code:
#include <IRremote.h>
#include <SD.h>
#include <TMRpcm.h>

#define SD_ChipSelectPin 10
#define powercode 0xA10CA00F
#define stormcode 0xA10C4C03 

int RECV_PIN = 8;
int yellow = 0;
int red = 1;
int red2 = 2;
int yellow2 = 3;
int blue = 4;
int purple = 5;
int purple2 = 6;
int white = 7;
long randOn;

IRrecv irrecv(RECV_PIN);
decode_results results;
TMRpcm tmrpcm;

void setup(){
 
  tmrpcm.speakerPin = 9;
  SD.begin(SD_ChipSelectPin);
 
  pinMode(red, OUTPUT);
  pinMode(red2, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(yellow2, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(purple, OUTPUT);
  pinMode(white, OUTPUT);
  pinMode(purple2, OUTPUT);           
  irrecv.enableIRIn(); // Start the receiver
}

int redbool = 0;
int orangebool = 0;
int yellowbool = 0;
int greenbool = 0;
int bluebool = 0;
int purplebool = 0;
int whitebool = 0;
int rgbbool = 0;
int rainbowbool = 0;
int sunbool = 0;
int rainbool = 0;
int stormbool = 0;
int powerbool = 1;
int lightningLoop = 1;

unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results)) {
                   
//Sun

    if (results.value == 2464125561) {
      if (millis() - last > 250) {
        sunbool = !sunbool;
        if (sunbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
         
          digitalWrite (white, HIGH);
          digitalWrite (yellow, HIGH);
          digitalWrite (yellow2, HIGH);
          tmrpcm.play("birds.wav");
          }
      }
      last = millis();
    }
   
 //rain

    if (results.value == 2278412527) {
      if (millis() - last > 250) {
        rainbool = !rainbool;
        if (rainbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (blue, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (red2, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (yellow2, LOW);
          digitalWrite (purple, LOW);
          digitalWrite (purple2, LOW);

          tmrpcm.play("balls.wav");
          digitalWrite (white, HIGH);
          digitalWrite (blue, HIGH);
          }
      }
      last = millis();
    }
   
//storm

    if (results.value == 930645859) {
      if (millis() - last > 250) {
        stormbool = !stormbool;
        if (stormbool == 0) {
          digitalWrite (red, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (blue, HIGH);
          digitalWrite (purple, HIGH);
          digitalWrite (purple2, HIGH);
          digitalWrite (white, LOW);
        }
      else {
          digitalWrite (red, LOW);
          digitalWrite (yellow, LOW);
          digitalWrite (white, LOW);

          digitalWrite (blue, HIGH);
          digitalWrite (purple, HIGH);
          digitalWrite (purple2, HIGH);
          tmrpcm.play("thunder.wav");
              randOn = random (10, 200);
              //Lightning Below
                 digitalWrite(white, HIGH);
                 delay(randOn); 
                 digitalWrite(white, LOW);
                 delay(randOn); 
                 digitalWrite(white, HIGH);
                 delay(randOn + randOn);   
                 digitalWrite(white, LOW);
               }
               }
      last = millis();
    }
 //rainbow
 
        if (results.value == 2769913147) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        rainbowbool = !rainbowbool;
       
        digitalWrite(white, LOW);
        digitalWrite(red, rainbowbool ? HIGH : LOW);
        digitalWrite(red2, rainbowbool ? HIGH : LOW);
        digitalWrite(yellow, rainbowbool ? HIGH : LOW);
        digitalWrite(yellow2, rainbowbool ? HIGH : LOW);
        digitalWrite(blue, rainbowbool ? HIGH : LOW);
        digitalWrite(purple, rainbowbool ? HIGH : LOW);
        digitalWrite(purple2, rainbowbool ? HIGH : LOW);
        tmrpcm.play("rainbow.wav");
      }
      last = millis();
    }   
   
 //red
 
        if (results.value == 1558024125) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        redbool = !redbool;
        digitalWrite(red, redbool ? HIGH : LOW);
        digitalWrite(red2, redbool ? HIGH : LOW);
      }
      last = millis();
    }
   
//orange

    if (results.value == 4382025) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        orangebool = !orangebool;
        digitalWrite(red, orangebool ? HIGH : LOW);
        digitalWrite(red2, orangebool ? HIGH : LOW);
        digitalWrite(yellow, orangebool ? HIGH : LOW);
        digitalWrite(yellow2, orangebool ? HIGH : LOW);
      }
      last = millis();
    }
   
//yellow

    if (results.value == 834338975) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        yellowbool = !yellowbool;
        digitalWrite(yellow, yellowbool ? HIGH : LOW);
        digitalWrite(yellow2, yellowbool ? HIGH : LOW);
      }
      last = millis();
    }
   
//green

    /*if (results.value == 356487335) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        greenbool = !greenbool;
        digitalWrite(green, greenbool ? HIGH : LOW);
        digitalWrite(green2, greenbool ? HIGH : LOW);
      }
      last = millis();
    }*/
   
//blue

    if (results.value == 1752348172) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        bluebool = !bluebool;
        digitalWrite(blue, bluebool ? HIGH : LOW);
      }
      last = millis();
    }
   
//purple

    if (results.value == 1851193636) {
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        purplebool = !purplebool;
        digitalWrite(purple, purplebool ? HIGH : LOW);
        digitalWrite(purple2, purplebool ? HIGH : LOW);
      }
      last = millis();
    }
   
//white

    /*if (results.value == 1181142029) { // TIVO button
      // If it's been at least 1/4 second since the last
      // IR received, toggle the relay
      if (millis() - last > 250) {
        whitebool = !whitebool;
        digitalWrite(white, whitebool ? HIGH : LOW);
        digitalWrite(white2, whitebool ? HIGH : LOW);
      }
      last = millis();
    }*/
    irrecv.resume();
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah,It seems like the code is fine but the program will not "pause" and play tmrpcm
Logged

Offline Offline
Jr. Member
**
Karma: 6
Posts: 87
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmmm its still giving me some trouble.  smiley-confuse No audio yet. It seems like the code is fine but the program will not "pause" and play   tmrpcm.play("birds.wav"); or any of the others because it only plays the first millisecond or so. Is this a valid hypothesis or am I crazy?

Maybe, but I could be crazy too, and you can't let crazy people decide whether you're crazy or not, can you?

The audio library is designed to run asynchronously, so the code will still execute while the music plays. It should keep playing however, unless you specifically stop the playback.

To "pause' the main loop, you can use
Code:
 

tmrpcm.play("thunder.wav");
while(tmrpcm.isPlaying()){}

 

The IR library works fine with my Arduino Mega if the sounds are encoded at 8-11khz. Anything higher causes problems with the playback due to the excessive processing load. I don't have any other type of Arduino to test on at the moment but should work similarly on Uno, Nano, etc.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@TMRh20
Ah that's interesting. I didn't think about the sample rate being too high for the board to keep up. I encoded each of those .wav files to 16kHz for some decent audio so ill try 8kHz and see how that turns out.
Logged

Holland
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey there,

I'm having similar problems, wav-file not playing in combination with an LCD (16x2). WAV-files play ok stand-alone or in combination with an IR detetctor.
Are there any new insights on this matter?

Regards Peter Mooij
Logged

Holland
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey there,

I'm having similar problems, wav-file not playing in combination with an LCD (16x2). WAV-files play ok stand-alone or in combination with an IR detetctor.
Are there any new insights on this matter?

Regards Peter Mooij
Tuesday 15 oct 2013: Found the problem, had to do with short on internal memory. Changed a few Serial.prinln( to Serial.println(F( and it works!!!
Logged

Pages: [1]   Go Up
Jump to: