open file with push buttons

Hello, I am working on an assignment where I have to have a speaker output a certain file. I want it to open and play a file named bird when P3 gets a high and play the file named hello when p4 gets a high. I have it set up with push buttons and I can only get the bird sound to play so far. What would I have to change to have the hello file start playing when p4 gets a high? Here is the code I have so far. Thanks


#include "simpletools.h"
#include "wavplayer.h"
#include "ping.h"
int main() // main function
{
int DO = 22, CLK = 23, DI = 24, CS = 25; // SD I/O pins
sd_mount(DO, CLK, DI, CS); // Mount SD card
const char bird[] = {"bird.wav"}; // Set up bird string
wav_play(bird); // Pass to wav player

while(1)
{
int button = input(3);
{
if(button == 1) button = 6;
wav_volume(button);
}
}
const char hello[] = {"hello.wav"}; // Set up hello string
wav_play(hello);

while(1)
{
int button = input(4);
{
if(button == 1) button = 6;
wav_volume(button);
}
}
}

Comments

  • 3 Comments sorted by Date Added Votes
  • Although not exactly, you would need something similar to the following
    #include "simpletools.h"
    #include "wavplayer.h"
    #include "ping.h"
    
    int main() // main function
    {
    	const char hello[] = {"hello.wav"}; // Set up hello string
    	const char bird[] = {"bird.wav"}; // Set up bird string
    
    	 // SD I/O pins
    	int DO = 22;
    	int CLK = 23;
    	int DI = 24;
    	int CS = 25;
    
    	sd_mount(DO, CLK, DI, CS); // Mount SD card
    
    	while(1)
    	{
    		if(input(3))
    		{
    			wav_play(bird);
    		}
    
    		if(input(4))
    		{
    			wav_play(hello);
    		}
    	}
    }
    


    Novel Solutions - http://www.novelsolutionsonline.com/ - Machinery Design • - • Product Development
    "Necessity is the mother of invention." - Author unknown.

  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited April 29 Vote Up1Vote Down
    Programmer's rule #0:
    computers do exactly what you tell them to do.

    :)

    Your code, as it stands, cannot play the hello. IDbruce's does.
    Note his use of indentation for code blocks. Doing it that way will help immensely; in fact, it's really the only sane way to code.
    schro.png
  • Thanks for the help. I was able to figure it out.
Sign In or Register to comment.