1 / 27

Basic Concepts of Programming November 3, 2012

Basic Concepts of Programming November 3, 2012. Before you begin…. Good programs: Take time Can be easily read Are easy to improve upon The best way to make a good program is to break the project up into smaller tasks. General LabVIEW Info.

saenz
Télécharger la présentation

Basic Concepts of Programming November 3, 2012

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Concepts of Programming November 3, 2012

  2. Before you begin… Good programs: • Take time • Can be easily read • Are easy to improve upon The best way to make a good program is to break the project up into smaller tasks.

  3. General LabVIEW Info • Dataflow is from left to right – the wires show the order the code is run • If two different blocks of code are not connected in any way, they will run at the same time when the VI starts • Pressing ctrl+h in labview shows a dialog box that briefly summarizes each icon function as well as wire data.

  4. Function Palette • This box contains the operations that will be used while coding. • The programming header contains the operations that will be used most frequently.

  5. Picture of Function Palette

  6. LabVIEW Constants Basic Constant Types • Numeric • Strings (usually words) • Boolean (true or false?)

  7. Controls • Usually trigger parts of a program • Come in many forms such as buttons, knobs and dropdown boxes (known as ring controls in LabVIEW)

  8. Indicators • Show outputs • Examples: graphs, gauges, slide fills

  9. Loops 2 main types in programming: “while” and “for” Biggest difference: while can be infinite, for is always finite For Loops While Loop

  10. While Loops Called “while loops,” because the code keeps running while a condition is met (whilex < 5, whilex ≠ 7, or while a = “false”) NOTE: Your code runs until the while loop condition is met. Stop Index

  11. Stopping While Loops

  12. Stopping While Loops (cont’d)

  13. Timing Changes Normally, while loops run as fast as your computer can allow them to run. However, that may be too fast for your program.

  14. Timing Changes (cont’d)

  15. Shift Registers • Shift registers remember the value that occurs at the end of the loop and bring it back to the beginning of the loop. • Shift registers can be found in both while and for loops. • Shift registers usually have to be initialized (this means, set the first value).

  16. Example without Shift Registers Initialize

  17. Example with Shift Registers Shift Registers

  18. While Loop Example • Make a while loop that does the following • Increments an integer by 1 every loop iteration • Multiplies a double by 2 every loop iteration • Displays both of these numbers • Waits .5 seconds for each loop iteration • Has a stop button to terminate the loop

  19. Solution

  20. For Loops For loops are a special type of while loop that can only be stopped when it has run a set number of times.

  21. For Loops Usage: Arrays For loops are great for making arrays in LabVIEW Array- indexed list of similar elements [4, 7, 12, 16, 25] : an array of numbers [dog, cat, bird, fish] : an array of animal words

  22. For Loop Array Example Array Indicator Count Random Numbers Index

  23. Case Statements You can divide your code to run when certain conditions are met. Case statements should be used in while loops. This code adds 1 every second the button is pushed down.

  24. Case Statement Example (False) Case: False

  25. Case Statement Example (True) Case: True

  26. Activity • Write code to simulate an input device • Using a while loop, two case structures, and two buttons, have two counters that increment by 1 for each unit of time that each button is pressed • If button 1 is pressed, counter 1 will increment • If button 2 is pressed, counter 2 will increment • If both buttons are pressed, both counters will increment

  27. Solution

More Related