LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add Pause Button

Solved!
Go to solution

Hello, I have a program. I want to add a pause button in my program. I have searched how to make it, but I'm still confused to implement it in my program. I hope someone can give clues, Thanks.

0 Kudos
Message 1 of 10
(5,428 Views)

Hi Michael,

 

to add that button you just drop a boolean button and change its label to "Pause"...

 

The more important question is: what do you want the button to act on?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(5,402 Views)

when I click the pause button, the program stops and when I click again the pause button, the program runs again.

0 Kudos
Message 3 of 10
(5,396 Views)

@michaelkeane24 wrote:

when I click the pause button, the program stops and when I click again the pause button, the program runs again.


The program should always run. "Pausing" is just one possible state (where it at least monitors the pause button for any changes).

0 Kudos
Message 4 of 10
(5,346 Views)

I would start over and redesign the code as a simple state machine. You don't need any local variables!

 

Here is a translation of the game (using google translate of the front panel text):

 

PROCEDURES FOR PLAYING SELECTION BALL GAME

1. Before the game starts, the player must choose the desired game speed.
     There are three options to choose from, namely Slow (4 seconds per turn), Medium (3 seconds per
     turn), and Fast (2 seconds per turn).
2. The player must choose the red ball when the player is playing. Player
     will get 1 correct ball.
3. If a player chooses the wrong ball, the player will get 1 ball
     is wrong.
4. The game will end if it meets one of the following conditions:
     a. The correct ball reaches 30
     b. The wrong ball reaches 15.
     c. The player clicks on the Stop button.
5. After the game ends, the player will see a dialog that displays
     whether the player wins or loses, the total score, the correct total ball, and the total ball
     wrong.

0 Kudos
Message 5 of 10
(5,344 Views)
Solution
Accepted by topic author michaelkeane24

Some comments to your code:

 

  • Way too much duplicate code! You 21 cases differ by very little, everything else belongs outside the case.
  • You don't need a shift register for the total. The value is always right+wrong count.
  • Code like the following makes absolutely no sense! Right? No need for any arrays! 
  • altenbach_0-1588880718167.png
  • Don't maximize the front panel and diagram to the screen! You need to be able to look at the help window at all times too!
  • An "Equal FALSE?" is just an "NOT", just delete it and swap the cases!
  • Your won and lose cases differ by a single little string. Why all that duplicate code???
  • Just display the result on a one button (OK) dialog. No need for all these extra buttons!
  • I would recommend to use a cluster of LEDs (can be transparent). Much simpler code!
  • Your random number is not fair! (0 and 20 will only occur at half the probability of the others).
  • I don't think you need to constantly disable/enable anything
  • ...

 

It can be done with <5% of the code (Your VI is 408kB, mine is 19kB!)! Attached is a quick draft that can give you some ideas. Let me know if anything is not clear. It would be easy to add the disable/enable feature, but I don't think it is needed.

 

altenbach_1-1588881939700.png

 

0 Kudos
Message 6 of 10
(5,336 Views)

Thank you so much, Sir.

0 Kudos
Message 7 of 10
(5,280 Views)

I want to ask, I want to use State Machine Architecture to make this program later, is that possible to do that? I'm still studying State Machine Architecture and Cluster Function, thank you Sir.

0 Kudos
Message 8 of 10
(5,278 Views)

It already is a (very primitive) state machine with two states: paused or not. 

0 Kudos
Message 9 of 10
(5,247 Views)
Okay Sir
0 Kudos
Message 10 of 10
(5,227 Views)