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

  • 4 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 2017 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.
  • AwesomeCronkAwesomeCronk Posts: 369
    edited April 11 Vote Up0Vote Down
    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.

    Mine gets really out of hand sometimes, but it is useful. In SPIN, I believe indentation is required on "repeat" and "if" commands.
    The greatest thing about logic is that, once you have followed the thought train, it is then your own.
Sign In or Register to comment.