Shop OBEX P1 Docs P2 Docs Learn Events
open file with push buttons — Parallax Forums

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

  • 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);
    		}
    	}
    }
    
  • CounterRotatingPropsCounterRotatingProps Posts: 1,132
    edited 2017-04-29 23:52
    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.
  • Thanks for the help. I was able to figure it out.
  • AwesomeCronkAwesomeCronk Posts: 1,055
    edited 2018-04-11 21:53
    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.
Sign In or Register to comment.