open file with push buttons
sokin
Posts: 32
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);
}
}
}
#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
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.
Mine gets really out of hand sometimes, but it is useful. In SPIN, I believe indentation is required on "repeat" and "if" commands.