LabVIEW Basic Course (2) ----Virtual Lottery Machine

This section focuses on introducing the program structure issues in LabVIEW.

There are For loops, While loops, conditional structures, event structures, sequence structures and block diagram disabled structures in LabVIEW. Students who have been exposed to other programming languages ​​​​should know the usage of these structures literally. Here I will take a simple game I made - Mini Lottery Machine to give you a demonstration to understand these structures in LabVIEW. usage.

The picture below is the lottery interface of the mini lottery machine. The interface is a little simple. I will package the program and put it at the end of the article, and you can make modifications by yourself.

Steps for usage:

                 1. Enter the names to be drawn one by one in the Name box, and click Add. All the numbers to be drawn will be written into the Listbox.

                 2. After all the lottery numbers are written, click START, the Running light will light up, and the lucky draw will start to flash in the show box.

                 3. After clicking Stop, a lucky person will be drawn and taken out of the Listbox and put into the Lucky boy/girl.

                 4. Then repeat 2 and 3 to draw lucky ones from the Listbox in a loop. If there is no lottery in the Listbox, the End light will turn red.

                 5. During the game, click Reset to restore the initial interface, re-enter the lot to be drawn, and restart the draw. Click Exit to exit the draw platform.

The figure below is the program block diagram of the lottery machine

       The program block diagram is carried out in the form of a state machine. The outer frame is a While loop. The red dot in the lower right corner determines whether the loop continues. Assign True to the red dot to exit the While loop, and assign False to continue the loop. The big box and the small box one level inside are both conditional structures. In the middle of the top of the structure is the judgment condition in the conditional structure. It will judge the input condition at the "?" on the conditional structure box to select the corresponding Condition page, execute the corresponding function. Right-click the top middle position to add the conditions to be judged.

       The innermost larger box is the event structure, which is a little more advanced than the other structures. It can judge the actions of the front panel and controls to execute the corresponding program. Right-click the top middle position of the mouse and select Add Event Branch, then select the control and select the event action of the control (press, drag action, and control value change). It should be noted here that the event structure is very convenient to use for some simple small programs, but many people are prone to abuse it and find that some events are not executed, or the program may be stuck, then it is necessary to check the event structure at this time Used, usually a While loop can only hold one event structure, and when the program executes to the event structure, it will wait for the event to arrive and execute before it can continue to execute. You should explore the use of event structures in subsequent programming!

       For the sequential structure, it is like a photo film, which is composed of frame by frame. Each frame is placed with the program to be executed, and the program will be executed in frame order. This is mainly because some parts of the program are executed in sequence. In the next section I will bring a larger mini-game that uses this structure. The block diagram disable structure is used to annotate the program. Programs that are not needed temporarily can be framed by the block diagram disable structure.

Lottery machine program code download:
link: https://pan.baidu.com/s/1-AbzyMirhyIumk6VLnWgMA 
extraction code: g16d

Guess you like

Origin blog.csdn.net/gougouainiuniu/article/details/128372111