170 likes | 279 Views
CS320n –Visual Programming. LabVIEW Control Structures. What We Will Do Today. Learn about control structures in LabVIEW class work working with control structures. For Loop. Just like in Alice, execute some code a fixed number of times
E N D
CS320n –Visual Programming LabVIEW Control Structures
What We Will Do Today • Learn about control structures in LabVIEW • class work working with control structures LabVIEW Control Structures
For Loop • Just like in Alice, execute some code a fixed number of times • In LabVIEW the loop is dragged around the components to be executed repeatedly LabVIEW Control Structures
For Loop Mechanics Count terminal. Wire a number to this. Could be constant orresult of operation Iteration terminal. Which execution of the loop is this? Starts at 0, not 1! LabVIEW Control Structures
Count value • Loops can’t execute fractional times • 0, 1, 2, 3, 4 … • Try wiring a floating point number to the count terminal • Not an error • normal rounding Coercion Dot LabVIEW Control Structures
Expected Output? • how many times does the loop execute? • what is the first value of the iteration counter? the last? • tough to see • add time delay LabVIEW Control Structures
Slowed down loop LabVIEW Control Structures
While loop • continue executing until while some condition is true (or until some condition is false) • condition can be anything that has a boolean output • output of function or result of a switch or button LabVIEW Control Structures
While Loop – Stopping Conditions Stop if true Continue if true Right click to change LabVIEW Control Structures
While loop • Pick and display random numbers until a number greater than .99 is selected • Tunnel – takes information out of a loop when finished LabVIEW Control Structures
Shift Registers • To get information from one iteration of a loop to the next shift register are used • Pick random numbers and add them together until the sum exceeds 1000 • How to keep a running total of them sum? LabVIEW Control Structures
Does Not Work • Why not? LabVIEW Control Structures
Fix with Shift Register • right click on loop boundary and choose “add shift register” Data from last iteration of loop. Give initial value. Data to nextiteration of loop LabVIEW Control Structures
Completed Version LabVIEW Control Structures
Class work • Create a LabVIEW program that picks random numbers • Pick random numbers until a value greater than 0.9999 is picked – while loop • Display how many picks it takes to get a result greater than 0.9999 • Run the experiment 10,000 times • What is the average number of picks required? – use a for loop • When that is finished add to the program to answer these questions: • What were the maximum and minimum number of picks required? LabVIEW Control Structures