Difference between revisions of "Exercise - Creating a Flowchart"
From Flowcode Help
Jump to navigationJump to searchJohnVerrill (talk | contribs) |
JohnVerrill (talk | contribs) |
||
Line 4: | Line 4: | ||
The program itself may form part of a bigger program. | The program itself may form part of a bigger program. | ||
+ | |||
+ | __TOC__ | ||
+ | |||
+ | ==Formulate the sequence== | ||
The flowchart sequence will be: | The flowchart sequence will be: | ||
: Check if the switch is pressed. | : Check if the switch is pressed. | ||
:: If it isn't, go back to the beginning. | :: If it isn't, go back to the beginning. | ||
:: If it is: | :: If it is: | ||
− | ::: | + | ::: switch on the lamp; |
− | ::: | + | ::: wait for 10 seconds; |
− | ::: | + | ::: switch off the lamp; |
− | ::: | + | ::: go back to the beginning. |
[[File:Gen_Running_Flowcode_Startup_Selection.png||250px|right]] | [[File:Gen_Running_Flowcode_Startup_Selection.png||250px|right]] | ||
It takes such a short time for the microcontroller to carry this out, that we don't need to worry whether the switch latches on or not. | It takes such a short time for the microcontroller to carry this out, that we don't need to worry whether the switch latches on or not. | ||
+ | ==Set up the flowchart== | ||
* Open Flowcode. | * Open Flowcode. | ||
* On the Startup screen, click on 'New embedded project'. (See [[Opening Flowcode]] | * On the Startup screen, click on 'New embedded project'. (See [[Opening Flowcode]] | ||
Line 41: | Line 46: | ||
: The System Panel and Properties Panel can be moved by 'clicking and dragging the title bar at the top of each panel. | : The System Panel and Properties Panel can be moved by 'clicking and dragging the title bar at the top of each panel. | ||
+ | |||
+ | |||
+ | ==Set up the input== | ||
* Drag and drop a 'Loop' icon between the Begin and End icons. | * Drag and drop a 'Loop' icon between the Begin and End icons. | ||
: The 'Loop' icon makes the microcontroller repeatedly run through the program, (though the icon can be configured to limit the number of times this happens.) | : The 'Loop' icon makes the microcontroller repeatedly run through the program, (though the icon can be configured to limit the number of times this happens.) | ||
[[File:Gen exerciseFirstFlowchart newvar 01.png|250px|right]] | [[File:Gen exerciseFirstFlowchart newvar 01.png|250px|right]] | ||
+ | |||
* Inside the loop, drag and drop an 'Input' icon from the Icons toolbar,. (See [[Tools and Views]].) | * Inside the loop, drag and drop an 'Input' icon from the Icons toolbar,. (See [[Tools and Views]].) | ||
:* Double click on the icon. | :* Double click on the icon. | ||
Line 49: | Line 58: | ||
:: This information will be contained in a variable called 'switch'. | :: This information will be contained in a variable called 'switch'. | ||
::* Click on the down arrow at the right-hand end of the 'Variable:' box to open the variables dialogue box. | ::* Click on the down arrow at the right-hand end of the 'Variable:' box to open the variables dialogue box. | ||
+ | |||
::* Hover to the left of the 'Variables' label and click on the down arrow that appears. | ::* Hover to the left of the 'Variables' label and click on the down arrow that appears. | ||
::* Click on the 'Add new' option to open the 'Create a New Variable' dialogue box. | ::* Click on the 'Add new' option to open the 'Create a New Variable' dialogue box. | ||
::* Create a new variable named "switch" with initial value "0" and description "Copies the state of the switch" | ::* Create a new variable named "switch" with initial value "0" and description "Copies the state of the switch" | ||
+ | |||
::* Leave the 'Variable type:' as 'Byte'. | ::* Leave the 'Variable type:' as 'Byte'. | ||
::: (For more information about variables, see [[Creating Variables]] and [[Variable Types]]. | ::: (For more information about variables, see [[Creating Variables]] and [[Variable Types]]. | ||
::: (The resulting dialogue box is shown opposite.) | ::: (The resulting dialogue box is shown opposite.) | ||
− | |||
− | |||
[[File:gen_exerciseFirstFlowchart_inputprops_01.png|250px|right]] | [[File:gen_exerciseFirstFlowchart_inputprops_01.png|250px|right]] | ||
+ | |||
+ | :* Finish configuring the input properties as follows: | ||
+ | ::* Change the 'Display name:' to "Read the switch". | ||
+ | ::* In the 'Variable:' box, type the name of the variable you created "switch". | ||
+ | ::* Leave the 'Port:' as PORT A. | ||
+ | ::* Select to 'Input from:'Single Bit' and choose bit 0. | ||
+ | ::: (The resulting dialogue box is shown opposite.) | ||
+ | |||
+ | |||
+ | : Set up like this, the program monitors the state of the switch. | ||
+ | : When the program looks at the input switch if it is pressed, the variable 'switch' contains logic 1. If unpressed, it contains logic 0. | ||
+ | |||
+ | |||
+ | |||
+ | ==Control the lamp== |
Revision as of 13:07, 11 June 2013
The task is to produce a Flowcode flowchart that lights a lamp for ten seconds when a switch is pressed.
Although it may not be realistic to use a microcontroller in such a straight-forward application, it illustrates the technique of producing a Flowcode program.
The program itself may form part of a bigger program.
Formulate the sequence
The flowchart sequence will be:
- Check if the switch is pressed.
- If it isn't, go back to the beginning.
- If it is:
- switch on the lamp;
- wait for 10 seconds;
- switch off the lamp;
- go back to the beginning.
It takes such a short time for the microcontroller to carry this out, that we don't need to worry whether the switch latches on or not.
Set up the flowchart
- Open Flowcode.
- On the Startup screen, click on 'New embedded project'. (See Opening Flowcode
- The Project Options dialogue box opens.
- (Click on the link for a full explanation of all the options available.)
- Accept the default settings by clicking on 'OK'.
- An empty flowchart window opens, which may contain other items such as a System Panel, Dashboard Panel, Properties Panel etc.
- These can be revealed or hidden using the View menu.
- Set up the flowchart window so that you can see the System Panel and the Properties Panel.
- The flowchart window should resemble the one shown below (depending on the configuration.)
- The System Panel and Properties Panel can be moved by 'clicking and dragging the title bar at the top of each panel.
Set up the input
- Drag and drop a 'Loop' icon between the Begin and End icons.
- The 'Loop' icon makes the microcontroller repeatedly run through the program, (though the icon can be configured to limit the number of times this happens.)
- Inside the loop, drag and drop an 'Input' icon from the Icons toolbar,. (See Tools and Views.)
- Double click on the icon.
- This opens the 'Properties: Input' dialogue box, allowing you to configure the way the program treats information from the switch.
- This information will be contained in a variable called 'switch'.
- Click on the down arrow at the right-hand end of the 'Variable:' box to open the variables dialogue box.
- Hover to the left of the 'Variables' label and click on the down arrow that appears.
- Click on the 'Add new' option to open the 'Create a New Variable' dialogue box.
- Create a new variable named "switch" with initial value "0" and description "Copies the state of the switch"
- Leave the 'Variable type:' as 'Byte'.
- (For more information about variables, see Creating Variables and Variable Types.
- (The resulting dialogue box is shown opposite.)
- Finish configuring the input properties as follows:
- Change the 'Display name:' to "Read the switch".
- In the 'Variable:' box, type the name of the variable you created "switch".
- Leave the 'Port:' as PORT A.
- Select to 'Input from:'Single Bit' and choose bit 0.
- (The resulting dialogue box is shown opposite.)
- Set up like this, the program monitors the state of the switch.
- When the program looks at the input switch if it is pressed, the variable 'switch' contains logic 1. If unpressed, it contains logic 0.