Chapter 4, Write the Program |
Top Previous Next |
In this chapter, we will add some useful code to the "Greenhouse_1.VPL" file.
We begin by defining the various signals we need either to monitor or to control from the program:
In the file, find the following code:
// Input variables that can be configured via the configuration dialog
Then modify it to read:
// Input variables that can be configured via the configuration dialog
This defines the two signals we need to monitor from the outside world, as well as the "Alarm_time" and "phone_number", which will be set from the configuration dialog.
Now, locate the following code in the file:
// Output variables that can be configured via the configuration dialog
And change it to look like this:
// Output variables that can be configured via the configuration dialog
This defines the two signals we need to control in the outside world.
Your program now looks like this:
//-----------------------------------------------------------------------------
Please note that we have not in any way connected the four signals to any specific physical in- or outputs, we have not even written anything about whether they are digital in- or output signals at all. This will be done in the Configuration, which will be covered in Chapter 6.
To save your work, you can press the "Save current file" on the standard toolbar:
Now we will add the variables of the program. Locate the following:
// The global variables of the program
And modify it to read:
// The global variables of the program
Now it is time to add some code to the program. First we will add some initialisation code.
Locate the following:
// The next code will only be executed once after the program starts
And modify it to read:
// The next code will only be executed once after the program starts
Now we will add the rest of the program. Locate the following:
BEGIN
And modify it to read:
BEGIN
To save your work, you can press the "Save current file" on the standard toolbar:
Now your complete program looks like this:
//-------------------------------------------------------------------------------
Congratulations! You have already come a long way, but now it is off to:
Chapter 5 Build the project
|