LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help in playing sound while LEDs are counting down

Hello, I am very new to Labview and this is my first time writing a post in the forum so I hope that what I am trying to write here make sense to everyone. 

 

 

I have managed to do a countdown of the LEDs. I have also found out that by using a sound file read I am able to play a .wav file in labview. I would like to know if it is possible to connect both of them together ( when I press run, both the .wav file and the LED will countdown as seen in the file). 

 

I sincerely apologize if this is an easy question but I do not know how to start and I hope that someone will help to solve my issue. Thanks.

Download All
0 Kudos
Message 1 of 9
(3,182 Views)

Start by putting the read of wave file and output sound into the Loop.  Have it in a case structure that only runs on the first iteration of the while loop.

 

The next issue you'll have is syncrhonizing the beeps to the lights.  You have a 900 msec wait in your loop, does that match the time between beeps in the wave file?  Otherwise, 900 msec seems rather coarse and unlikely to coincide with a countdown that I would naturally expect to be once per second.

 

You might get better synchronization if you had shorter waveform files where there is one for the first beeps, and one for the last one.  they could play as soon as your condition to light an LED is true.

 

But start by doing what I said, see how it goes, and tweak from there

0 Kudos
Message 2 of 9
(3,157 Views)

Hello thanks for the quick reply.

 

I have tried my very best to do what you have told me to. After numerous attempts of trying and googling for the solution, this is the best result ( though the sound is not playing at all).

 

My first attempt was to include the read wave file and sound output in the while loop. The result was that it even though it plays the sound, the LEDs are not blinking at all. 

 

After an hour of searching, I managed to get the LEDs blinking but the sound is not working.

 

I hope that I am not asking too much but is it ok if you help me to edit and take a screenshot of it ( asking for the VI file may be too much) so that I can have a comparison of where did I go wrong please? 

 

0 Kudos
Message 3 of 9
(3,114 Views)

I have attached some working code for you (Using the beep function because I didn't have a sound file close to hand)

 

I have also annotated your original code to give you some idea of why yours wasn't working.

0 Kudos
Message 4 of 9
(3,104 Views)

You've got a math problem.

 

What do you think the chances are that the differences between two timestamps at a millisecond resolution will ever be exactly 1 second apart in order for that case structure to turn true?

 

It also looks like that express VI blocks halts execution until the sound file completely plays.  (I wasn't sure if it or another sound VI would just start the file and LabVIEW would continue playing it in a separate thread.)

 

You putting the sound file outside of the loop and have it start based on a notification from the while loop.

 

Please don't post VI's with the front panels and block diagrams maximized to full screen.  It makes it hard to work between the two.  And set the front panel so all of the controls are near each other so you can see them all when the VI is in a smaller window.   Bring things together and size the window to fit.  Use block diagram cleanup as well to improve the appearance of the diagram.

0 Kudos
Message 5 of 9
(3,086 Views)

Thanks RavensFan and Niatross for the reply. 

 

With the help of the two of you, I have managed to come up with a sound system in labview as seen in the file attached. The reason why I included the small Flat Sequence Structure on the right is because in the original VI, there is a scoring system formula included inside. I am doing the sound system and hence I tried to make as similar as the original VI.

 

Yesterday, I saw an interesting function in labview called " Display message to User". I was thinking that after the " Game over sound effect" has finished playing, labview will display a message asking the user if they want to continue with the game. There will be two button at the bottom--- yes and no buttons. If the user clicks on yes, the game process will repeat and if the user clicks on no, the game will end. 

 

I was thinking if it is possible. Do I need to use Event structure instead of Case Structure? Sorry for asking so many questions! 

Download All
0 Kudos
Message 6 of 9
(3,044 Views)

I just noticed that we are also able to prompt users to input data. Does labview allow this to happen:

 

Firstly, when I press run, it will prompt user to input their names. After typing their names and pressing ok, the game will run together with the sound system. After the " game over" sound effect finished playing, it will then display a message to the user to ask if they want to continue with the game. If yes, the game will restart and if no, the game will end.

 

I hope that this is manageable even for a newbie like me, and I sincerely apologize for asking too many questions again. 

0 Kudos
Message 7 of 9
(3,032 Views)

Hello. I have this Simulation build whereby players are able to play the game and contains music. After noticing that labview has this function called "Display Message to user", I would like to include it inside my coding.

 

I would like the "Display message to user" function to appear it after the game has ended ( after the 20 seconds duration) which shows a message that says " Do you want to continue?" and below there are two buttons-- yes and no buttons. If the person presses yes, the game will restart and if the person presses no, it will stop. Is it possible to do it? I am quite new to labview and I do not know how to start. Do I need to use event structure for this? 

 

I hope that someone will be able to solve my issue. 

 

PS: Does myrio allow people to save wave files and play in the NI Dashboard for labview in IPad? We also would like to send all of the data, including the wave files, to NI Dashboard for labview. ( We know how to send sensor values and the GUI in labview to NI Dashboard by using Shared Variable, but we are still unsure if myrio allows people to send wave files to the dashboard). I hope what I have written so far make sense to everyone. 

0 Kudos
Message 8 of 9
(3,049 Views)

Hi eledale,

 


@eledale wrote:

I would like the "Display message to user" function to appear it after the game has ended ( after the 20 seconds duration) which shows a message that says " Do you want to continue?" and below there are two buttons-- yes and no buttons. If the person presses yes, the game will restart and if the person presses no, it will stop. Is it possible to do it? I am quite new to labview and I do not know how to start. Do I need to use event structure for this? 


This is very basic LabVIEW stuff once you know to THINK DATAFLOW and how to use loops:

 

Now I looked into your project: come on and clean up this huge block diagram!

Remove all that Rube-Goldberg stuff, use wires instead of local variables, think about a state machine instead of a huge sequence structure, use loops instead of duplicate code, create meaningful subVIs, …

 

This is what the last frame might look like:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Download All
0 Kudos
Message 9 of 9
(3,024 Views)