Go Down

Topic: wav player with led's controling by ethernet (Read 1 time) previous topic - next topic


Jan 21, 2013, 04:59 pm Last Edit: Jan 21, 2013, 05:07 pm by mcmarek Reason: 1
Hello guys. I've got problem with interrupts (I guess?). First of all I describe the scheme. I using the arduino UNO + ethernet shield. There is a speaker connected to GND and PWM~9, and led's conected to 6,5 pins. I've got a 3 wav files on sd card. Everything works separately, but all at once won't. I can control the led's via ethernet, also I can control the sound using console. The problem comes when I tried to change led sequence during the song is playing. I using the TMRpcm library and standard Ethernet. Here is the code:

Code: [Select]

#include <Ethernet.h>
#include <SPI.h>
#include <SD.h>                      
#define SD_ChipSelectPin 4  //using digital pin 4
#include <TMRpcm.h>

TMRpcm tmrpcm;  

unsigned long time = 0;

boolean reading = false;

short unsigned int choice=3;

short int Speaker=9;
short int LedOne=5;
short int LedTwo=6;

int LedOneStat=0;
int LedTwoStat=0;

int x=0;

IPAddress ip(192,168,1, 177);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server(80); //port 80

void flash_all()

void flash_even()

void flash_1()

void flash_2()

void setup()
   if (!SD.begin(SD_ChipSelectPin))
       Serial.println("SD fail");  
       Serial.println("SD ok");  
   tmrpcm.play("lc1.wav"); //the sound file "music" will play each time the arduino powers up, or is reset


void loop()
   if(choice==2) flash_all();
   if(choice==3) flash_even();
   if(choice==4) flash_1();
   if(choice==5) flash_2();
       case 'a':
       case 'b':
       case 'c':
       case 'p':
       case '?':
           if(tmrpcm.isPlaying()) Serial.println("A wav file is being played");
           else Serial.println("A wav file isn't playing");
       case 'S':


void checkForClient()

 EthernetClient client = server.available();

 if (client) {

   // an http request ends with a blank line
   boolean currentLineIsBlank = true;
   boolean sentHeader = false;
   while (client.connected()) {
     if (client.available()) {

         // send a standard http response header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         sentHeader = true;

       char c = client.read();

       if(reading && c == ' ') reading = false;
       if(c == '?') reading = true; //found the ?, begin reading the info


          switch (c) {
           case '2':
           case '3':
           case '4':
           case '5':


       if (c == '\n' && currentLineIsBlank)  break;

       if (c == '\n') {
         currentLineIsBlank = true;
       }else if (c != '\r') {
         currentLineIsBlank = false;


   delay(1); // give the web browser time to receive the data
   client.stop(); // close the connection:



I think the interrupts are overlap. But my knowledge is not very impressive. Can anyone help me figure it out?
Thanks for all replays.

PS. Sorry for my limited english. It's my secound language.

I check everything once again and I find out that problem is flash_all(). i can set all others sequences of led's and it's work's. I think the problem could be that the led's have a diffrent specification, and if I turn on the 'ONE', i can't turn on the 'TWO'(not exacly, i can turn them on but still only one is flashing). So I have to quicky change the pwm's voltage. Any ideas?


Hi!! could it be possible that you control the led and at the same you can control the song playing on the speaker through ethernet??

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131