<< Chapter < Page Chapter >> Page >
The creation of this content was supported in some part by NSF grant 0538934.

The heart of interactive programming in G is the while loop . Any input control within the while loop can be modified from the Front Panel window at run time to provide seamless interaction with the G program.

A small diagram containing a small blue box containing an 'i' in the lower left hand corner and a red button icon on the lower right corner. In the middle of the diagram is a small box containing the phrase 'Interactive G Program'.
Creating Interactive Programs

In the Front Panel window, from the Functions>>Modern>>Numeric select the vertical pointer slide. From the Functions>>Modern>>Graph select Waveform Chart .

A diagram of a 'Vertical Pointer Slide and Waveform Chart'. There are two directory levels identified above two rows of three icons. The upper level is labeled  'Modern' and the level directly underneath that is labeled 'Numeric'. below 'Numeric' is a listing two rows of three icons.
Vertical Pointer Slide and Waveform Chart
A diagram of a 'Vertical Pointer Slide and Waveform Chart'. There are two directory levels identified above two rows of three icons. The upper level is labeled  'Modern' and the level directly underneath that is labeled 'Graph'. Below 'Graph' is a listing two rows of three icons.
Vertical Pointer Slide and Waveform Chart

Re-label the vertical pointer slide as Amplitude and the waveform chart as Sine Wave . Re-arrange to GUI to look like the figure below.

An empty graph.
Slide&Waveform Chart in Front Panel window

Right click on Sine Wave and select Properties from the pop-up menu.

An empty graph with a menu on top of it. The item 'Properties' is highlighted.
Selecting Chart Properties

Select the Scales tab and change Maximum to 1023. Sine Wave will display 1024 samples.

A screencap of a window with many tabs along the top of the window. The fourth tab 'scales' is selected. Then on this tab there are many fields with the lower right field surrounded by a red box and containing the number 1023 . This field is labeled Maximum.
X-Axis Maximum

Click on the down arrow located to the right of Time (X-Axis) and select Amplitude (Y-Axis) .

A screencap of a window with many tabs along the top of the window. The fourth tab 'scales' is selected and a drop down menu is selected with the menu item 'Time (X-Axis)' has a check mark next to it. The menu item 'Amplitude (Y-Axis)' is highlighted in blue.
Selecting Y-Axis

De-select Autoscale and change the Minimum and Maximum values to -10 and 10 . Click OK .

A screencap of a window with many tabs along the top of the window. The fourth tab 'scales' is selected. In the lower right of the tab is a red box surround a radio box labeled 'Autoscale' and two fields one labeled 'Minimum' containing the value '-10' and the other field is labeled 'Maximum' containing the value '10'.
De-Selecting Autoscale

Rearrange Amplitude and Sine Wave terminals and finish the program as shown in [link] .

Scroll the mouse pointer over the Loop Control

A screen cap of a diagram of an 'Interactive Sine Wave Diagram'. The diagram consists of several icons. From left to right the there is a orange box containing '0.02' and below that a blue box containing 'i'. Lines connect these boxes to a triangular box containing 'x. A line connects this to a wave icon which is connected to another triangular box containing 'x'. A line connects this triange to an icon labeled 'Sine Wave'. Below this row of icons there is an icon labeled 'Amplitude' that is connected to the second triangle. A red button icon is located in the bottom right corner.
Interactive Sine Wave Diagram
A screen cap of a diagram of an 'Interactive Sine Wave Diagram'. The diagram consists of several icons. From left to right the there is a orange box containing '0.02' and below that a blue box containing 'i'. Lines connect these boxes to a triangular box containing 'x. A line connects this to a wave icon which is connected to another triangular box containing 'x'. A line connects this triange to an icon labeled 'Sine Wave'. Below this row of icons there is an icon labeled 'Amplitude' that is connected to the second triangle. A red button icon is located in the bottom right corner. This button icon has a mouse arrow over it and below the mouse is box containing 'Loop Condition'.
Loop Condition

And right click on the Loop Control and from the pop-up menu select Create Control .

A stop terminal is created.

A screen cap of a diagram of an 'Interactive Sine Wave Diagram'. The diagram consists of several icons. From left to right the there is a orange box containing '0.02' and below that a blue box containing 'i'. Lines connect these boxes to a triangular box containing 'x. A line connects this to a wave icon which is connected to another triangular box containing 'x'. A line connects this triange to an icon labeled 'Sine Wave'. Below this row of icons there is an icon labeled 'Amplitude' that is connected to the second triangle. A red button icon is located in the bottom right corner. Over this button there is a menu with the menu item 'Create Control' highlighted in blue.
A screen cap of a diagram of an 'Interactive Sine Wave Diagram'. The diagram consists of several icons. From left to right the there is a orange box containing '0.02' and below that a blue box containing 'i'. Lines connect these boxes to a triangular box containing 'x. A line connects this to a wave icon which is connected to another triangular box containing 'x'. A line connects this triange to an icon labeled 'Sine Wave'. Below this row of icons there is an icon labeled 'Amplitude' that is connected to the second triangle. A red button icon is located in the bottom right corner. To the left of this button is a 'stop' icon connected to it via a line.
Interactive G Program

With the corresponding stop Boolean input control. Save the G program as Interactivity.vi .

An empty graph.
Interactive Program

Run the G program.

A graph with an straight line running along y=0.
Interactive Program

While the program is running, change the Amplitude and watch the graph update to reflect the interactive changes.

A graph with a sine wave with an amplitude of 6.93878
Interactive Program

To end the G program, simply click on the stop button.

A graph with a sine wave with an amplitude of 6.93878. The stop button to the left of the wave is highlighted Red.
Interactive Program

Congratulations. You have successfully completed and executed your first interactive G program.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to g programming. OpenStax CNX. Mar 15, 2010 Download for free at http://cnx.org/content/col11192/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to g programming' conversation and receive update notifications?

Ask