<< Chapter < Page | Chapter >> Page > |
The selected diagram is highlighted as shown in [link]
From the Edit menu select Create SubVI to create a G function. The resulting diagram is shown in [link] .
From the File menu select Save All and save the Untitled function as Fahrenheit to Celsius.vi .
Open the Fahrenheit to Celsius.vi by double clicking on the icon. Right click on the icon editor (upper right corner) and select Edit Icon…
This pops-up the Icon Editor . Edit the function’s icon.
After editing the icon, the function’s icon is shown in the upper right corner of the Front Panel window. Save the function, plug in various input values and run the function. Save the function.
Close the Fahrenheit to Celsius function and return to the Celsius Block Diagram windows. The Celsius diagram reflects the updated Fahrenheit to Celsius icon
This program determines if a year is a leap year or not. A leap year is divisible by 4 but not by 100, except when it is divisible by 400. A number x is divisible by a number y if the remainder of x/y is identical to zero, i.e. Rem(x/y)=0 is true therefore
where And , Or and Not are Boolean operators.
For example:
1900 is not a leap year because it is divisible by 100
1970 is not a leap year because it is not divisible by 4
1980 is a leap year because it is divisible by 4 but not by 100
2000 is a leap year because it is divisible by 400
Start a new G program and right click on the Block Diagram window. Go to the Functions>>Programming>>Numeric menu in the Block Diagram window.
Select three copies of the Quotient&Remainder function and three numeric constants. Type in 4, 100 and 400 for the numeric constants and wire these constants to the lower input terminal (corresponding to the dividend) of the Quotient&Remainder function.
From the Functions>>Programming>>Comparison menu, select 2 copies of the Equal to Zero function and one copy of the Not Equal to Zero function.
Organize the comparison operations as show in the diagram.
From the Functions>>Programming>>Boolean menu select the AND and OR operators
Place the Boolean operators as shown in [link] .
From the Functions>>Programming>>Structures menu, click on the Case Structure .
Click and drag on the Block Diagram window to create the Case Structure .
The True diagram option is indicated at the top of the case structure.
Drop a string constant and type “Is a Leap Year”.
Click on the down arrowhead next to the True label and select the False option.
Drop another string constant and type “Is not a Leap Year”.
Go to the Front Panel window and place a numeric input and an output string. Re-label the numeric input to Year and the output string to Message .
Right click on Year and select Representation>>I32 from the numeric pop-up menu.
Notification Switch
Would you like to follow the 'Introduction to g programming' conversation and receive update notifications?