Counter (Example)
Load the model counterParts.mdl from the Model window.
This is how the tree looks:
Display the top level. This is how the GUI looks:
Try to make it work and you get error messages because the buttons are not linked to anything. It won't even display a value. We will now fix that.
We need to create a variable:
1 |
Click on the Model Variables tab. The page will show an empty table. |
2 |
In the Name field type n and in the Value field type 0, the initial value. |
Now we link the variable n to the Monitor (Edit Text) box:
1 |
Click on the Model GUI Items tab and select the item Monitor (Edit Text). |
2 |
Double-click it to bring up the Properties dialog. |
3 |
In the Options list click on Field Value. |
4 |
In the Edit dialog (at the right) click on Track Variable. |
5 |
Click on the Variable box, and type n, the click on the Apply box underneath. |
6 |
The Field Value will now be displayed as Field Value (Variable n). |
7 |
The Edit Text box is now linked to the variable n. |
8 |
Click on the bottom left OK button. |
We now create macros to execute when the buttons are pressed:
1 |
Click on the Macros tab. |
2 |
Click on New from the left menu. |
3 |
In the dialog box type the macro name reset, and click OK. |
4 |
Under the Select Macro: heading click on reset. |
5 |
In the blank page on the right type n = 0. |
- This is the contents of the macro named reset.
6 |
Now create two more macros: |
- countUp contains the text: n = n + 1
- countDown contains the text: n = n - 1
We now link the buttons to the macros:
1 |
Click on the Model GUI Items tab. |
2 |
Double-click the countUp push button in the tree. |
3 |
In the Properties dialog, under Callbacks, click on Button Pressed. |
4 |
In the Edit dialog enter |
|
• |
The macro name countUp as the first argument. |
|
• |
The action Execute as the second argument. |
5 |
Click on Apply underneath. |
- The callback will now show
- Button Pressed (iccap funct("countUp","Execute"))
6 |
Repeat this for the other two buttons, linking them to the macros with the same names. |
The counter will now count up, count down and reset:
|