<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.flowcode.co.uk/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=JohnVerrill</id>
	<title>Flowcode Help - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.flowcode.co.uk/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=JohnVerrill"/>
	<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Special:Contributions/JohnVerrill"/>
	<updated>2026-04-30T14:46:20Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Sidebar:_Panel_Exercises&amp;diff=11161</id>
		<title>Sidebar: Panel Exercises</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Sidebar:_Panel_Exercises&amp;diff=11161"/>
		<updated>2013-09-01T14:00:59Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*Flowcode Wiki&lt;br /&gt;
**Main Page|Main page&lt;br /&gt;
**portal-url|portal&lt;br /&gt;
**randompage-url|randompage&lt;br /&gt;
**helppage|helppage&lt;br /&gt;
*SEARCH&lt;br /&gt;
*Panel Exercises&lt;br /&gt;
**Exercises | Exercises&lt;br /&gt;
**Exercise - System Panel - Adding Objects  | Adding Objects to the System Panel&lt;br /&gt;
**Exercise - System Panel - Controlling Shapes | Controlling Shapes on the System Panel&lt;br /&gt;
**Exercise - Dashboard Panel - Adding Objects | Adding Objects to the Dashboard Panel&lt;br /&gt;
**Exercise - Dashboard and System Panel - Controlling Multiple Objects | Controlling Multiple Objects&lt;br /&gt;
**Exercise - System Panel - Controlling Collisions | Controlling Collisions on the System Panel&lt;br /&gt;
*TOOLBOX&lt;br /&gt;
*LANGUAGES&lt;br /&gt;
&lt;br /&gt;
[[Category:Sidebar]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Importing_and_Testing_the_Traffic_Cone&amp;diff=11160</id>
		<title>Exercise - Importing and Testing the Traffic Cone</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Importing_and_Testing_the_Traffic_Cone&amp;diff=11160"/>
		<updated>2013-09-01T14:00:00Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Component Exercises&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
[[File:gen_exercisetestconeimport_macroprops_01.png|300px|right]]&lt;br /&gt;
* [[Creating Flowcharts|Create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* The following assumes that you have built, and exported a traffic cone component, as described in [[Exercise - Building a Complex Component|Building a Complex Component - a traffic cone]] and [[Exercise - Exporting the Traffic Cone Component|exporting the traffic cone]].&lt;br /&gt;
&lt;br /&gt;
* Open the 'Misc' toolbox, and locate the exported 'traffic cone' component. &lt;br /&gt;
&lt;br /&gt;
* Use the down-arrow next to it to add it to the [[System Panel]].&lt;br /&gt;
&lt;br /&gt;
* Create a flowchart to test the imported component:&lt;br /&gt;
&lt;br /&gt;
:* Add a component macro to the flowchart, and double-click on it. &lt;br /&gt;
&lt;br /&gt;
:* Click on the 'Simulation' tab, and then on the 'flash' macro that appears in the macro list. &lt;br /&gt;
&lt;br /&gt;
:* Then click on 'OK'. &lt;br /&gt;
&lt;br /&gt;
* Your flowchart should now resemble the one shown below:&lt;br /&gt;
[[File:gen_exercisetestconeimport_flowchart_01.png|200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Simulate the flowchart, (see [[Exercise - Simulating a Program]]), to test whether the import has worked.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Building_a_Complex_Component&amp;diff=11159</id>
		<title>Exercise - Building a Complex Component</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Building_a_Complex_Component&amp;diff=11159"/>
		<updated>2013-09-01T13:59:28Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Component Exercises&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise shows how to create a traffic cone with a double flashing lamp, using the 'newLED' component.&lt;br /&gt;
The settings and dimensions given are found by trial-and-error, or by using the cursor and cursor position settings shown at the bottom of the [[System Panel]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Setting up the LED component==&lt;br /&gt;
* [[Creating Flowcharts|Open a new Flowcode flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Ensure that the [[System Panel]] is visible. If not use the [[View]] menu.&lt;br /&gt;
&lt;br /&gt;
* The following assumes that you have built, and exported a LED component, as described in [[Exercise - Create an LED Component]] and [[Exercise - Exporting the LED Component]].&lt;br /&gt;
[[File:gen_exerciseBuildComplexComp_complex1.png|180px|right]]&lt;br /&gt;
* Open the 'Outputs' toolbox, where you stored the exported 'newLED' component.&lt;br /&gt;
&lt;br /&gt;
* Locate the 'newLED' component, and use the down-arrow next to it to add it to the [[System Panel]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Click on the LED to select it. Change the 'color' property to orange (e.g. 0x0080FF).&lt;br /&gt;
&lt;br /&gt;
* Using the Panel Properties, with the LED still selected, set its 'Position' to X=0, Y=0, Z=10, and its 'Scale' to 'Wi...'=1, 'He...'=1, 'De...'=0.25. &lt;br /&gt;
: The component should resemble the picture opposite, (depending on the 'camera' zoom.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Adding the second LED==&lt;br /&gt;
[[File:gen_exerciseBuildComplexComp_complex2_01.png|180px|right]]&lt;br /&gt;
* Click on the head of the vertical arrow, (green), to rotate the camera to give an 'edge-on' view.&lt;br /&gt;
&lt;br /&gt;
* The LED should still be selected. If not, click on it. Right-click and select the 'Copy' option. Then right-click and select the 'Paste' option. &lt;br /&gt;
: A second identical LED appears. &lt;br /&gt;
&lt;br /&gt;
* Set its 'Position' co-ordinates to X=0, Y=0, Z=-10, and the 'Rotation' settings to X=0, Y=180, Z=0. &lt;br /&gt;
: The System panel should now resemble the one shown opposite:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Mounting the LEDs==&lt;br /&gt;
[[File:gen_exerciseBuildComplexComp_complex3_01.png|180px|right]]&lt;br /&gt;
* Drag and drop a cube onto the System Panel.&lt;br /&gt;
&lt;br /&gt;
* Select it, and set its 'Position' co-ordinates to X=0, Y=0, Z=0, and 'Scale' to 'Wi...'=32, 'He...'=12, 'De...'=32. &lt;br /&gt;
&lt;br /&gt;
* Change its 'color' property to mid-grey (e.g. 0x5A5A5A).&lt;br /&gt;
&lt;br /&gt;
: The System Panel looks like the one opposite:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Building the traffic cone==&lt;br /&gt;
* Drag across all three shapes and group them by clicking on the 'Group' icon.[[File:Gen_Panel_Object_Group_01.png|border]]&lt;br /&gt;
* Notice that the 'Component Handle' and 'Type' have changed to 'Group'. Rename the 'Handle' as &amp;quot;flasher&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Click on the head of the vertical arrow, (blue), to rotate the camera back to the 'head-on' view.&lt;br /&gt;
&lt;br /&gt;
* Drag and drop a cone onto System Panel.&lt;br /&gt;
&lt;br /&gt;
* Select it, and set its 'Position' co-ordinates to X=0, Y=-12, Z=0, 'Scale' to 'Wi...'=45, 'He...'=45, 'De...'=120 and 'Rotation' to X=-90, Y=0, Z=0. &lt;br /&gt;
&lt;br /&gt;
* Change its 'color' to red (e.g. 0x0000C0).&lt;br /&gt;
&lt;br /&gt;
* View it from different 'camera' directions by clicking on the heads of the red, green and blue arrows. It should resemble the picture shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery widths=180px perrow=3 caption=&amp;quot;Three views&amp;quot;&amp;gt;&lt;br /&gt;
File:gen_exerciseBuildComplexComp_complex4_01.png&lt;br /&gt;
File:gen_exerciseBuildComplexComp_complex5_01.png&lt;br /&gt;
File:gen_exerciseBuildComplexComp_complex6_01.png&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Revert to the original (left-hand side) view.&lt;br /&gt;
&lt;br /&gt;
* Drag and drop a cylinder onto the System Panel.&lt;br /&gt;
&lt;br /&gt;
* Give it the following settings:&lt;br /&gt;
:: 'Position' - X=0, Y=-75, Z=0; &lt;br /&gt;
:: 'Scale' -'Wi...'=60, 'He...'=60, 'De...'=10; &lt;br /&gt;
:: 'Rotation' - X=-90, Y=0, Z=0.&lt;br /&gt;
&lt;br /&gt;
* Change its 'color' to dark red (e.g. 0x000080).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The completed traffic cone==&lt;br /&gt;
* Drag across all three shapes and group them by clicking on the 'Group' icon.&lt;br /&gt;
&lt;br /&gt;
::::: The System Panel now looks like this:[[File:gen_exerciseBuilbComplexComp_complex7_01.png|middle|180px]]&lt;br /&gt;
&lt;br /&gt;
==Adding an interface==&lt;br /&gt;
The next task is to make the cone do something - flash on and off.&lt;br /&gt;
&lt;br /&gt;
* Click on 'Macro' and then 'New' to create a new macro.&lt;br /&gt;
* In the 'Create a  New Macro dialogue box, name the new macro &amp;quot;flash&amp;quot; and click on 'OK'.&lt;br /&gt;
* On the 'flash' macro workspace:&lt;br /&gt;
:* add an infinite loop, and inside the loop:&lt;br /&gt;
::* drag and drop a 'Simulation macro' icon;&lt;br /&gt;
:::* double click on it. Rename it &amp;quot;Switch on&amp;quot;. Click on the 'Simulation' tab, and on one of the 'LEDon' labels and click on 'OK'.&lt;br /&gt;
::* drag and drop a 'Delay' icon. &lt;br /&gt;
:::* double click on it. Change its name to &amp;quot;One second delay&amp;quot;. Change the units to 'seconds' and click on 'OK'.&lt;br /&gt;
::* drag and drop a second 'Simulation macro' icon;&lt;br /&gt;
:::* double click on it. Rename it &amp;quot;Switch off&amp;quot;. Click on the 'Simulation' tab, and on one of the 'LEDoff' labels and click on 'OK'.&lt;br /&gt;
::* drag and drop a second 'Delay' icon, and configure it exactly as before.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
The 'flash' flowchart now resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:Gen exercisetest LEDimport testflowchart.png|200px|center]][[File:gen_exerciseBuildComplexComp_flashmacro_01.png|250px|right]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
* In the 'Main' part of the flowchart, drag and drop a 'Macro' icon.&lt;br /&gt;
:* Double click on it and then click on the 'flash' label.&lt;br /&gt;
* Test the component by simulating the program. &lt;br /&gt;
:* See the [[Exercise - Simulating a Program]]&lt;br /&gt;
&amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt; &amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==What next?==&lt;br /&gt;
* The traffic cone component can now be exported in the usual way. (See [[Exercise - Exporting the Traffic Cone Component|Exporting the Traffic Cone]].)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Dashboard_and_System_Panel_-_Controlling_Multiple_Objects&amp;diff=11158</id>
		<title>Exercise - Dashboard and System Panel - Controlling Multiple Objects</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Dashboard_and_System_Panel_-_Controlling_Multiple_Objects&amp;diff=11158"/>
		<updated>2013-09-01T13:58:08Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Panel Exercises&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise shows how to add two more LEDs to the car's instrument panel, each controlled separately by switches on the [[Dashboard Panel]]. These will warn the driver that the sidelights are switched on, and that a seatbelt is not fastened.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Open the 'Headlight warning' flowchart==&lt;br /&gt;
&lt;br /&gt;
* [[Opening an Existing Flowchart|Open the flowchart]] 'Headlight warning' which you created in [[Exercise - Dashboard Panel - Adding Objects]].&lt;br /&gt;
: This uses one switch, labeled 'main', operating an orange LED on the instrument panel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the LEDs==&lt;br /&gt;
&lt;br /&gt;
* Add two more 'Single LEDs to the [[System Panel]]. &lt;br /&gt;
: Do this either from the 'Outputs' toolbox, as you did for the first LED, or by 'copying and pasting' that LED. [[File:gen_exercisemulticontrol_finalinstpan_01.png|300px|right]]&lt;br /&gt;
&lt;br /&gt;
* In either case, &lt;br /&gt;
: give one coordinates 'X'= -60, 'Y'=-55, 'Z'=-1.75, and color it green;&lt;br /&gt;
: give the other coordinates 'X'= 60, 'Y'=-55, 'Z'=-1.75, and color it blue. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: All three LEDs should have the same size ('Wi...' =32, 'He...'=32, 'De...'=10).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: The System Panel now resembles the one shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Connect the LEDs==&lt;br /&gt;
The original LED is connected to PORT A, bit 1.&lt;br /&gt;
* Click on the each of the added LEDs in turn, and use the Panel Properties to connect:&lt;br /&gt;
:: the left-hand LED (green) to PORT A, bit 0, &lt;br /&gt;
:: the right-hand (blue) LED to PORT A, bit 2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the switches==&lt;br /&gt;
[[File:gen_exercisemulticontrol_multidash_01.png|300px|right]]&lt;br /&gt;
* Add two more 'Toggle Metal Panel' switches to the Dashboard Panel. &lt;br /&gt;
: As above, you can do this either from the 'Inputs' panel or by 'copying and pasting' the first switch. &lt;br /&gt;
: In either case, give one coordinates 'X'= 30, 'Y'=5, 'Z'=-2, and the other coordinates 'X'= 60, 'Y'=5, 'Z'=-2. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: All three switches should have the same size ('Wi...' =2, 'He...'=2, 'De...'=1).&lt;br /&gt;
&lt;br /&gt;
* Create two further labels, either by dragging them onto the Dashboard panel, using the 'T' icon, or by copying and pasting the 'side' label. &lt;br /&gt;
: In either case, rename one &amp;quot;side&amp;quot;, and give it coordinates 'X'=30, 'Y'=-15, 'Z'=0.5. &lt;br /&gt;
: Rename the other &amp;quot;belt&amp;quot; and give it coordinates 'X'=60, 'Y'=-15, 'Z'=0.5. &lt;br /&gt;
: All three labels should be the same size, ('Wi...' =10, 'He...'=10, 'De...'=2).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: The Dashboard Panel now resembles the one shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Connect the switches==&lt;br /&gt;
The original 'main' switch is attached to PORT B, bit 0. &lt;br /&gt;
* Connect the switch above the 'side' label to PORT B, bit 1, and the one above the 'belt' label to PORTB,2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Binary arithmetic==&lt;br /&gt;
Before creating the Flowcode program, here is a little background in binary arithmetic. The switches don't have to be read as separate items. Instead, they can  be used to control the first three bits of a binary number applied to PORT B. The table shows the input binary number resulting from different combinations of switch presses:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center; margin:auto; color: black;&amp;quot; width=&amp;quot;40%&amp;quot;&lt;br /&gt;
! belt &amp;lt;br /&amp;gt; bit 2 !! main &amp;lt;br /&amp;gt; bit 1!! side &amp;lt;br /&amp;gt; bit 0!! binary &amp;lt;br /&amp;gt; no.!! decimal &amp;lt;br /&amp;gt; no.&lt;br /&gt;
|-&lt;br /&gt;
|0||0||0||000||0&lt;br /&gt;
|-&lt;br /&gt;
|0||0||1||001||1&lt;br /&gt;
|-&lt;br /&gt;
|0||1||0||010||2&lt;br /&gt;
|-&lt;br /&gt;
|0||1||1||011||3&lt;br /&gt;
|-&lt;br /&gt;
|1||0||0||100||4&lt;br /&gt;
|-&lt;br /&gt;
|1||0||1||101||5&lt;br /&gt;
|-&lt;br /&gt;
|1||1||0||110||6&lt;br /&gt;
|-&lt;br /&gt;
|1||1||1||111||7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The way this works:&lt;br /&gt;
: The 'belt' switch is worth '4' in decimal, because it controls the third binary digit, and so is worth 2&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (=4). &lt;br /&gt;
: The 'main' switch is worth '2' in decimal, because it controls the second binary digit, and so is worth 2&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt; (=2). &lt;br /&gt;
: The 'side' switch is worth '1' in decimal, because it controls the first binary digit, and so is worth 2&amp;lt;sup&amp;gt;0&amp;lt;/sup&amp;gt; (=1).&lt;br /&gt;
&lt;br /&gt;
When more than one switch is pressed, the number generated, (whether in binary or decimal,)is equal to the sum of these values.&lt;br /&gt;
So, when the 'belt' switch and the 'side' switch are both pressed, the number produced is '5'.&lt;br /&gt;
&lt;br /&gt;
The Flowcode program senses this number using the 'Switch' icon.&lt;br /&gt;
&lt;br /&gt;
==Creating the Flowcode flowchart==&lt;br /&gt;
* Modify the 'Headlight warning' program as follows:&lt;br /&gt;
:* Double-click on the 'Input' icon to open the dialogue box.&lt;br /&gt;
::* Change the 'Input from:' setting from 'Single Bit:' to 'Entire Port:'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
: (The program now reads all devices connected to PORT B, and so inputs the number generated by the three switches.)&lt;br /&gt;
[[File:gen_exercisemulticontrol_switchcaseconfig_01.png|300px|right]]&lt;br /&gt;
:* Click on the 'Decision' icon, to select it, and then delete it (by pressing on the 'Delete' key, for example.)&lt;br /&gt;
:* Drag and drop a 'Switch' icon to replace it.&lt;br /&gt;
&lt;br /&gt;
::* Double-click on it to open the dialogue box, and then:&lt;br /&gt;
:::* Rename it &amp;quot;Input&amp;quot;.&lt;br /&gt;
:::* Insert the variable name &amp;quot;input&amp;quot; in the box following the label 'Switch:'.&lt;br /&gt;
:::* There are eight possible combinations of switches, giving input numbers up to 111 (7 in decimal), so click to add ticks to the boxes from 1 to 7.&lt;br /&gt;
:::: The dialogue box resembles the one shown opposite.&lt;br /&gt;
:::* Click on 'OK'.&lt;br /&gt;
:* In the default branch, add an 'Output' icon, and double-click on it to configure it to output value 0 to the entire PORT A. Rename it &amp;quot;Switch off&amp;quot;.&lt;br /&gt;
:* In the '=1' branch, add an 'Output' icon, and double-click on it to configure it to output value 1 to the entire PORT A. Rename it &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:: This branch is activated when the 'side'light switch, alone, is pressed. The green warning light will come on as a result.&lt;br /&gt;
:* In the '=2' branch, add an 'Output' icon, and configure it to output value 2 to the entire PORT A. Rename it &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:: This branch is activated when the 'main' switch, alone, is pressed. The orange warning light will come on.&lt;br /&gt;
:* In the '=3' branch, add an 'Output' icon, and configure it to output value 3 to the entire PORT A. Again, rename it &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:: This branch is activated when both the 'side'light and 'main' switches are pressed. Both the green and orange warning lights will come.&lt;br /&gt;
:* In the '=4' branch, add an 'Output' icon, and configure it to output value 4 to the entire PORT A. Rename it &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:* Follow this with a 'Delay' icon, configured to give a delay of one second.&lt;br /&gt;
:* Then add a second 'Output' icon, configured to output value 0 to the entire PORT A, to switch the warning light off.&lt;br /&gt;
:* Then add a second 'Delay' icon, also configured to give a delay of one second.&lt;br /&gt;
:: This branch is activated when the 'belt' switch, alone, is pressed (because the seat belt is not in use.) The blue warning light flashes on an off repeatedly.&lt;br /&gt;
:* In the '=5' branch, add an 'Output' icon, and configure it to output value 5 to the entire PORT A. Rename it &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:* Follow this with a 'Delay' icon, configured to give a delay of one second.&lt;br /&gt;
:* Then add a second 'Output' icon, configured to output value 1 to the entire PORT A.&lt;br /&gt;
:* Then add a second 'Delay' icon, also configured to give a delay of one second.&lt;br /&gt;
:: This branch is activated when the 'side' and 'belt' switches are both activated. The program keeps the green warning light on, but makes the blue warning light flash on an off.&lt;br /&gt;
:* In the '=6' branch, add an 'Output' icon, and configure it to output value 6 to the entire PORT A. Rename it &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:* Follow this with a 'Delay' icon, configured to give a delay of one second.&lt;br /&gt;
:* Then add a second 'Output' icon, configured to output value 2 to the entire PORT A.&lt;br /&gt;
:* Then add a second 'Delay' icon, also configured to give a delay of one second.&lt;br /&gt;
:: This branch is activated when the 'main' and 'belt' switches are both activated. The program keeps the orange warning light on, but makes the blue warning light flash on an off.&lt;br /&gt;
:* In the '=7' branch, add an 'Output' icon, and configure it to output value 7 to the entire PORT A. Rename it &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:* Follow this with a 'Delay' icon, configured to give a delay of one second.&lt;br /&gt;
:* Then add a second 'Output' icon, configured to output value 3 to the entire PORT A.&lt;br /&gt;
:* Then add a second 'Delay' icon, also configured to give a delay of one second.&lt;br /&gt;
:: This branch is activated when all three switches are activated. The program keeps the green and orange warning lights on, but makes the blue warning light flash on an off.&lt;br /&gt;
The flowchart looks like the one below:&lt;br /&gt;
[[File:gen_exercisemulticontrol_multiprog1_01.png|1200px|center]]&lt;br /&gt;
* Simulate the program to check that it responds correctly when different combinations of the switches are pressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: '''Congratulations! You have completed the construction of the car instrument panel.'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_System_Panel_-_Controlling_Shapes&amp;diff=11157</id>
		<title>Exercise - System Panel - Controlling Shapes</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_System_Panel_-_Controlling_Shapes&amp;diff=11157"/>
		<updated>2013-09-01T13:57:20Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Panel Exercises&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
The following assumes that you have added a single LED to the [[System Panel]], as described in [[Exercise - System Panel - Adding Objects]].&lt;br /&gt;
&lt;br /&gt;
The aim of this exercise is to mount the LED on the car's instrument panel, and to control the viewpoint of the resulting component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Open the LED flowchart==&lt;br /&gt;
[[File:gen_exerciseSystemPanel_controlviewpoint_moveicon_01.png|300px|right]]&lt;br /&gt;
* Open the flowchart &amp;quot;System_Panel_Add_LED&amp;quot; which you created in [[Exercise - System Panel - Adding Objects]].&lt;br /&gt;
* Check that the Panel Properties is displaying sizes as 'World size'.&lt;br /&gt;
* Move the LED into the top right-hand corner by clicking on the 'Move with the mouse' icon.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the instrument panel==&lt;br /&gt;
* Click and drag a cylinder from the vertical toolbar onto the [[System Panel]].&lt;br /&gt;
[[File:gen_exerciseSystemPanelcontrolviewpoint_addcylinder_01.png|150px|right]]&lt;br /&gt;
* Click on it to select it. You will see five properties listed on the [[Properties Panel]],&lt;br /&gt;
: 'Shape', 'Color', 'Outline', 'Thickness' and 'Image'.&lt;br /&gt;
* The default 'Color' property is red (0x0000C0). Click on its value, and change the color to black (0x000000).&lt;br /&gt;
&lt;br /&gt;
==Change the shape of the instrument panel==&lt;br /&gt;
[[File:gen_exerciseSystemPanelcontrolviewpoint_scaleicon_01.png|300px|right]]&lt;br /&gt;
* Click on the 'Scale with mouse' icon on the top, horizontal toolbar.&lt;br /&gt;
: Now, when you select the cylinder, eight drag handles appear around the edges.&lt;br /&gt;
: These allow you to reshape the cylinder by dragging on the appropriate handle.&lt;br /&gt;
&lt;br /&gt;
* Drag on one of the horizontal handles until the width of the cylinder is 120mm.&lt;br /&gt;
&lt;br /&gt;
* Drag on one of the vertical handles until the height is 60mm.&lt;br /&gt;
&lt;br /&gt;
* On the Properties Panel, set the depth (De...) to 3mm.&lt;br /&gt;
[[File:gen_exerciseSystemPanelshapecontrol_instpanel_01.png|200px|right]]&lt;br /&gt;
* Centre the cylinder by setting its position coordinates to 'X'=0, 'Y'=0, 'Z'=0, on the Properties Panel.&lt;br /&gt;
&lt;br /&gt;
* To make it look more realistic, locate the 'ADC dial' in the 'Inputs' toolbox. (This device can be used as an input device, but here it is being used as a decoration.)&lt;br /&gt;
* Click on the down-arrow to the left of the label, and select the 'Add to system panel' option. &lt;br /&gt;
* Click on the dial on the System Panel to select it and give it the following properties:&lt;br /&gt;
: 'Coordinates': X=0, Y=25, Z=5;&lt;br /&gt;
: 'World size': 'Wi...'=35, 'He...'=35, 'De...'=5;&lt;br /&gt;
&lt;br /&gt;
* Now add two more dials in the same way.&lt;br /&gt;
* Give one 'Coordinates': X=-100, Y=0, Z=5, and 'World size': 'Wi...'=15, 'He...'=15, 'De...'=5.&lt;br /&gt;
* Give the other one 'Coordinates': X=100, Y=0, Z=5, and 'World size': 'Wi...'=15, 'He...'=15, 'De...'=5.&lt;br /&gt;
&lt;br /&gt;
: The [[System Panel]] looks like the one opposite.&lt;br /&gt;
&lt;br /&gt;
==Add the LED to the instrument panel==&lt;br /&gt;
* Now, move the LED back into position by selecting it and setting its position coordinates to 'X'=0, 'Y'=-60, 'Z'=0.&lt;br /&gt;
: Doing it in this order ensures that the LED appears on top of the instrument panel.&lt;br /&gt;
&lt;br /&gt;
* Drag over both objects, and group them by clicking on the 'Group' icon. [[File:Gen_Panel_Object_Group_01.png|border]]&lt;br /&gt;
&lt;br /&gt;
* At this point, save the flowchart as &amp;quot;System_Panel_Add_MountedLED&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Change the viewpoint==&lt;br /&gt;
* Flowcode allows you to view these objects from different directions by changing the 'camera position' (viewpoint.)&lt;br /&gt;
&lt;br /&gt;
: The first method uses the red, green and blue arrows at the top left hand corner of the System Panel.&lt;br /&gt;
:: First, click on the arrowhead of the green arrow. &lt;br /&gt;
:: This gives you a view of the objects from the 'green' direction.&lt;br /&gt;
:: Now do the same with the head of the red arrow, to see them from the 'red' direction.&lt;br /&gt;
:: Finally, clicking on the head of the blue arrow takes you back to the original view.&lt;br /&gt;
&lt;br /&gt;
* There are three 'camera' controls that give finer control.&lt;br /&gt;
[[File:Gen Panel Object Move 01.png|left|border]]&lt;br /&gt;
: The first is the 'pan' control that allows you to move the viewpoint to one side.&lt;br /&gt;
:: To see this, click on the 'pan' control. Hold down the '''Ctrl''' key, and click the mouse anywhere on the System Panel.&lt;br /&gt;
:: As you move the cursor up and down or from side to side, the viewpoint moves accordingly.&lt;br /&gt;
:: Notice that the coordinates of the objects do not change. The objects stay in the same place, but they are viewed from a different place.&lt;br /&gt;
&lt;br /&gt;
: The second and third are 'camera rotation' controls.&lt;br /&gt;
[[File:Gen Panel Camera Orbit 01.png|left|border]]&lt;br /&gt;
[[File:Gen Panel Camera Rotate 01.png|left|border]]&lt;br /&gt;
:: Click on the first of these. Hold down the '''Ctrl''' key, and click the mouse anywhere on the System Panel.&lt;br /&gt;
:: As you move the cursor, the objects seem to rotate, though, if you look at the 'Rotation' settings on the Properties Panel, you see that these settings do not change. Again, it is the viewpoint that is changing.&lt;br /&gt;
:: Then, try the same with the other control.&lt;br /&gt;
&lt;br /&gt;
==Multiple views==&lt;br /&gt;
* A powerful feature of Flowcode 6 is the ability to view the components from a number of different directions simultaneously.&lt;br /&gt;
&lt;br /&gt;
* To see this:&lt;br /&gt;
[[File:Gen Panel General Options 01.png|left|border]]&lt;br /&gt;
: Click on the 'General options' icon.&lt;br /&gt;
: In 'Number of views:', click on the down-arrow and select &amp;quot;3&amp;quot;.&lt;br /&gt;
: By clicking on the appropriate arrowheads, set up each view as shown below.&lt;br /&gt;
: (Depending on the size and shape of the Systems Panel, the three views may be arranged vertically, instead of horizontally. &lt;br /&gt;
: Drag one edge of the Systems Panel sideways to see this effect. )&lt;br /&gt;
[[File:gen_exerciseSystemPanelshapecontrol_threeview1_01.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
* You can adjust the viewpoint individually for each view, by operating the 'camera position' controls.&lt;br /&gt;
: An example of doing so is given below - notice the positions of the red, green and blue arrows in each:&lt;br /&gt;
[[File:gen_exerciseSystemPanelshapecontrol_threeview2_01.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
* Alternatively, you can make changes to the objects themselves, in which case all three views are affected at once.&lt;br /&gt;
: In the next image, the instrument panel has been rotated:&lt;br /&gt;
[[File:gen_exerciseSystemPanelshapecontrol_threeview3_01.png|500px|center]]&lt;br /&gt;
: You can see what is happening by viewing the [[Properties Panel]]. Changes to the objects themselves result in changes to properties such as 'Coordinates' and 'World size'. &lt;br /&gt;
: Camera movement and rotation change the viewpoint, but do nothing to the properties of the objects themselves.&lt;br /&gt;
&lt;br /&gt;
==What next==&lt;br /&gt;
The next stage is to control the LED using a switch mounted on Flowcode's Dashboard Panel. This is covered in the exercise [[Exercise - Dashboard Panel - Adding Objects|Adding Objects to the Dashboard Panel]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Video instructions==&lt;br /&gt;
&lt;br /&gt;
See the [http://www.youtube.com/watch?v=5-IzDJ2NDcc&amp;amp;list=PLQDWBb7bxuCgg6aJgPJcfXBMzZdLILceQ Aligning Objects on the Panel 1] video to learn the basics of aligning objects on the panel, this video covers the all available options of the 'Snap to' function including Snap to '''''Grid''''', '''''Objects''''' and '''''Table top'''''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next video, [http://www.youtube.com/watch?v=okbJ9pJrEeA&amp;amp;list=PLQDWBb7bxuCgg6aJgPJcfXBMzZdLILceQ Aligning Objects on the Panel 2], expands onto manipulating objects by moving, rotating and scaling / re-sizing objects to align them on the panel, this video makes use of the [[Project Explorer]] in order to manipulate the objects precisely.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Finally, the [http://www.youtube.com/watch?v=0b0jtQzBS9Q&amp;amp;list=PLQDWBb7bxuCgg6aJgPJcfXBMzZdLILceQ Alignig Objects on the Panel 3] video details additional options to effectively align objects on the panel, this includes various options from the context menu when you right-click a selected object.&lt;br /&gt;
&lt;br /&gt;
{| style=&amp;quot;margin:auto; text-align:center;&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|{{#ev:youtube|5-IzDJ2NDcc}}&lt;br /&gt;
| width=&amp;quot;100px&amp;quot; |&lt;br /&gt;
|{{#ev:youtube|okbJ9pJrEeA}}&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; |&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| colspan=&amp;quot;3&amp;quot; |{{#ev:youtube|0b0jtQzBS9Q}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Interrupts&amp;diff=11156</id>
		<title>Exercise - Using Interrupts</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Interrupts&amp;diff=11156"/>
		<updated>2013-09-01T13:55:56Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is an Interrupt?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Interrupts are a way of grabbing the microcontroller's attention immediately.&lt;br /&gt;
&lt;br /&gt;
They are very widely used, both in microcontrollers and microprocessors. For example, the keyboard and mouse in your computer probably use interrupts to talk to the CPU.&lt;br /&gt;
&lt;br /&gt;
They can also be used to save energy. In many battery-powered applications, the microcontroller is 'put to sleep' when inactive, and so requires little energy. An interrupt is used to 'awaken' the controller, and bring it back into operation, when needed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This exercise shows how to use an interrupt to sense when a switch is closed, (an external interrupt).&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Polling vs interrupt==&lt;br /&gt;
&lt;br /&gt;
The microcontroller is often connected to a large number of peripheral input devices - switches, sensors, memory, timers etc. &lt;br /&gt;
There are two broad ways in which one of these devices can be serviced by the microcontroller:&lt;br /&gt;
* polling - each device is 'asked' in turn if it has data to transfer to the controller;&lt;br /&gt;
* interrupts - allow the device to interrupt the task being carried out by the controller.&lt;br /&gt;
&lt;br /&gt;
The exercise aims to show the difference between polling and using interrupts. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The system==&lt;br /&gt;
&lt;br /&gt;
This exercise sets up a system with LEDs controlled by two switches:&lt;br /&gt;
::* Switch 1 is polled by the program, at regular intervals.&amp;lt;br /&amp;gt;&lt;br /&gt;
::* Switch 2 initiates an interrupt.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The polled switch, switch 1, is checked at regular (and predictable) intervals - every six seconds in this example.&lt;br /&gt;
Switch 2 is connected so that as soon as it operates, the processor stops what it is doing and jumps to the Interrupt Service Routine (ISR). In the process, the return address is stored, so that at the end of the ISR, the processor can return to where it left the main program. In Flowcode, the ISR takes the form of a macro, configured like any other.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The flowchart==&lt;br /&gt;
&lt;br /&gt;
The flowchart sequence:&lt;br /&gt;
:* Check if switch 1 is pressed.&lt;br /&gt;
:: If it isn't, make the red LED flash slowly.&lt;br /&gt;
:: If it is, make the yellow LED flash slowly.&lt;br /&gt;
:* Go back to the beginning and repeat the process.&lt;br /&gt;
:* Whenever switch 2 is pressed, immediately make both LEDs flash quickly ten times and then go back to the main program.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The main program==&lt;br /&gt;
&lt;br /&gt;
* [[Creating Flowcharts|Start a new Flowcode flowchart]], using the default microcontroller.&lt;br /&gt;
&lt;br /&gt;
* Make sure that the [[System Panel]] is visible. If necessary, click on [[View]] and then select 'System Panel' a check-box will appear next to the option when enabled.&lt;br /&gt;
&lt;br /&gt;
* Drag and drop a [[Loop Icon Properties|Loop icon]] between the BEGIN and END icons.&lt;br /&gt;
&lt;br /&gt;
* Inside the loop, drag and drop an [[Input Icon Properties|Input icon]] from the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
&lt;br /&gt;
* Drag and drop a [[Decision Icon Properties|Decision icon]] after the 'Input' icon.&lt;br /&gt;
&lt;br /&gt;
Next, add icons to control what happens when switch is not pressed, (and so the program follows the 'No' branch):&lt;br /&gt;
&lt;br /&gt;
* Drag and drop an [[Output Icon Properties|Output icon]] in the 'No' branch.&lt;br /&gt;
: This icon is going to turn the red LED on.&lt;br /&gt;
&lt;br /&gt;
* Drag and drop a [[Delay Icon Properties|Delay icon]] after the 'Output' icon.&lt;br /&gt;
: This will keep the LED on for three seconds.&lt;br /&gt;
&lt;br /&gt;
* Follow it with another [[Output Icon Properties|Output icon]].&lt;br /&gt;
: This icon is going to turn the LED off.&lt;br /&gt;
&lt;br /&gt;
* Add a second [[Delay Icon Properties|Delay icon]] next.&lt;br /&gt;
: This will keep the LED off for three seconds.&lt;br /&gt;
&lt;br /&gt;
The program then loops back and checks the state of the switch again.&lt;br /&gt;
&lt;br /&gt;
Next, add icons to control what happens when switch is pressed, and so the program follows the 'Yes' branch:&lt;br /&gt;
&lt;br /&gt;
* Drag and drop an [[Output Icon Properties|Output icon]] in the 'Yes' branch.&lt;br /&gt;
&lt;br /&gt;
* Drag and drop a [[Delay Icon Properties|Delay icon]] after the 'Output' icon.&lt;br /&gt;
&lt;br /&gt;
* Follow it with another [[Output Icon Properties|Output icon]].&lt;br /&gt;
&lt;br /&gt;
* Add a second [[Delay Icon Properties|Delay icon]] next.&lt;br /&gt;
&lt;br /&gt;
The program then loops back, as before, and checks the state of the switch again.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add switch 1 and the LEDs ==&lt;br /&gt;
&lt;br /&gt;
* Locate the 'Inputs' toolbox, and click on the down arrow next to the switch labelled 'Toggle Metal PCB'.&lt;br /&gt;
: Click on the 'Add to system panel' option.&lt;br /&gt;
: Configure its properties so that it is connected to Port B, bit 1.&lt;br /&gt;
&lt;br /&gt;
* Locate the 'Outputs' toolbox, and click on the down arrow next to the 'LED array' label.&lt;br /&gt;
: Click on the 'Add to system panel' option.&lt;br /&gt;
* Click on one, and configure its properties as follows&lt;br /&gt;
:: set the 'Count' property to &amp;quot;2&amp;quot;, to give two LEDs in the array;&lt;br /&gt;
:: set the colour of LED0 to red, and that of LED1 to yellow.&lt;br /&gt;
:: LED0 will light when Port A is sent value '1', and LED1 will light when Port A is sent value '3';&lt;br /&gt;
:: check that the 'Connections' property shows that it is connected to Port A.&lt;br /&gt;
&lt;br /&gt;
Double click on each icon in the flowchart and configure it as shown in the following images:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery caption=&amp;quot;Configuring the icons&amp;quot; perrow=&amp;quot;6&amp;quot;&amp;gt;&lt;br /&gt;
File:Exercise_UsingInt_redLEDon.jpg|Turn the red LED on&lt;br /&gt;
File:Exercise_UsingInt_3sdelay.jpg|Three seconds delay&lt;br /&gt;
File:Exercise_UsingInt_LEDoff.jpg|Turn the LEDs off&lt;br /&gt;
File:Exercise_UsingInt_yellLEDon.jpg|Turn on the yellow LED&lt;br /&gt;
File:Exercise_UsingInt_sw1_prop.jpg|Configure switch 1&lt;br /&gt;
File:Exercise_UsingInt_decision.jpg|Configure the decision icon&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a larger version, double click on the image.&lt;br /&gt;
&lt;br /&gt;
Simulate the flowchart to make sure that the LEDs behave as expected.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add switch 2==&lt;br /&gt;
[[File:Exercise_UsingInt_int_prop.jpg|200px|right]]&lt;br /&gt;
&lt;br /&gt;
* Add a second 'Toggle Metal PCB' switch to the system panel.&lt;br /&gt;
: Configure its properties so that it is connected to Port B, bit 0 - the hardware interrupt bit.&lt;br /&gt;
* Drag and drop an interrupt icon [[File:Btn_Interrupt.gif|border]] between 'BEGIN'and the upper loop icon, (although it will work anywhere in the flowchart.)&lt;br /&gt;
: Double click on the icon, and configure it as shown opposite.&lt;br /&gt;
* The next task is to create the ISR. Click on the 'Create New Macro...' button.&lt;br /&gt;
[[File:Exercise UsingInt Int flashfastmacro.jpg|200px|right]]&lt;br /&gt;
&lt;br /&gt;
* The 'Create a New Macro' dialogue box opens. &lt;br /&gt;
: Give the macro the name &amp;quot;flash_fast&amp;quot;.&lt;br /&gt;
: Click on OK.&lt;br /&gt;
&lt;br /&gt;
* In the 'Properties:Interrupt' dialogue box, click on the 'OK &amp;amp; Edit Macro' button.&lt;br /&gt;
: Create the flowchart shown opposite for the macro.&lt;br /&gt;
: Sending value '3' (=00011 in binary,) to Port A switches on both LEDs.&lt;br /&gt;
&lt;br /&gt;
==The main flowchart==&lt;br /&gt;
&lt;br /&gt;
Your flowchart should now be set up to resemble the image below: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_UsingInt_main.jpg|350px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Test the system==&lt;br /&gt;
&lt;br /&gt;
Earlier, you tested the effect of switch 1 on the LEDs. Now you can test the effect of switch 2 as well.&lt;br /&gt;
* Run the simulation, and confirm the action of switch 1 on the LEDs.&lt;br /&gt;
* While Flowcode is simulating a three second delay, toggle switch 2 on and off.&lt;br /&gt;
: The  three second simulationshould stop, mid-delay, and both LEDs should flash quickly, ten times, as specified in the ISR.&lt;br /&gt;
: After this, the microcontroller resumes the main program from where it left off, the three second delay.&lt;br /&gt;
* Repeat the tests until you are happy with the way the system operates.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Inserting_Code_Into_Flowcode&amp;diff=11155</id>
		<title>Exercise - Inserting Code Into Flowcode</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Inserting_Code_Into_Flowcode&amp;diff=11155"/>
		<updated>2013-09-01T13:55:23Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
C code is a high-level programming language widely used in industry.&amp;lt;br /&amp;gt;&lt;br /&gt;
It has spawned a number of other programming languages, such as C#, C++, Java and Python. &lt;br /&gt;
&lt;br /&gt;
Flowcode programs are first compiled into C before being crunched down eventually into hex code. &lt;br /&gt;
&lt;br /&gt;
There are two mechanisms for adding your own C code to a Flowcode flowchart:&lt;br /&gt;
[[File:Exercise_InsCode_C_suppcode.jpg|right|350px]]&lt;br /&gt;
* using the 'C Code' icon   [[File:Btn C Code.gif|border]] ;&lt;br /&gt;
* using the 'Use supplementary code' facility within 'Project Options', shown opposite:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Why would you want to?==&lt;br /&gt;
&lt;br /&gt;
* Flowcode programs are compiled to 'C', but produce many lines of code. &lt;br /&gt;
: They do so because they must be able to cope with any function or structure that the designer wishes to use. &lt;br /&gt;
: Experienced C programmers may wish to use code more efficiently, and so insert a few lines of code to replace many lines which Flowcode would generate. (This usually applies to the 'Adding supplementary code' option.)&lt;br /&gt;
&lt;br /&gt;
* Experienced programmers can insert a short section of C code in order to reduce the length, or complexity, of the Flowcode program.&lt;br /&gt;
&lt;br /&gt;
* Students learning to program in C can test short sections of code by inserting them into a Flowcode program. This avoids having to write the full program in C.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature is used when you have blocks of code containing routines, definitions, lookup tables, etc.  &lt;br /&gt;
[[File:Gen_Supplementary_Code_01.png|right|frameless]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is the first section. It allows users to initialise the program, by adding structures such as 'defines', 'includes', and other function declarations.  This section must be placed at the beginning of the C file so that the code is 'visible' to all parts of the program.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;br /&gt;
&lt;br /&gt;
This second section allows for the addition of the main function code.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Structured thus, the code is accessible to any Flowcode macro, and vice-versa.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Warning==&lt;br /&gt;
&lt;br /&gt;
Be sure that the added C code is correct! &amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Flowcode does not simulate C Code, so programs that make use of supplementary code may not simulate correctly. &lt;br /&gt;
Where Flowcode fails to compile, it may be that the supplementary code contains errors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using the 'Code' icon==&lt;br /&gt;
[[File:Exercise_InsCode_C_Flowchart.png|right|294x261px]]&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
::* a loop icon, configured as an infinite loop;&lt;br /&gt;
::* a calculation icon:&lt;br /&gt;
:::* use it to create two byte variables, 'var1' and 'add',&lt;br /&gt;
:::* set them to the following values:&lt;br /&gt;
::::: var1 = 2, add = 3;&lt;br /&gt;
::* a Code icon [[File:Btn C Code.gif|border]]- details given below;&lt;br /&gt;
::* a delay icon configured to give a two second delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The C Code==&lt;br /&gt;
&lt;br /&gt;
Configure the Code icon by typing in the following code, exactly as written here:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:[cpp]&amp;quot; style=&amp;quot;float:left;&amp;quot;&amp;gt;&lt;br /&gt;
trisb = 0;                         //Set all of Port B to output &lt;br /&gt;
portb = FCV_VAR1;                  //Output the value of var1 to port B&lt;br /&gt;
trisa = 1;                         //Convert port A bit 0 to input&lt;br /&gt;
if (test_bit(porta,0))             //Check to see if A0 is high&lt;br /&gt;
{&lt;br /&gt;
portb = FCV_VAR1 + FCV_ADD;        //If so, portb = 2 + 3 = 5 (0101 in binary)&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
portb = FCV_VAR1;                 //Otherwise portb = 2&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The 'Code' icon properties box resembles that shown opposite.&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_InsCode_C_Code_Properties.png|center]]&lt;br /&gt;
&lt;br /&gt;
The software recognizes instructions and comments, and colour-codes them accordingly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Some notes on this code:'''&lt;br /&gt;
&lt;br /&gt;
* The ports on the PIC chip are bi-directional - they can act as either input or output.&lt;br /&gt;
* Their behaviour is controlled by the contents of two more registers - TRISA (for Port A) and TRISB (for Port B.)&lt;br /&gt;
:* A value of '0' in the control register makes the corresponding bit of the port into an output bit.&lt;br /&gt;
:* A value of '1' in the control register makes the corresponding bit of the port into an input bit.&lt;br /&gt;
* Commands are finished by adding a semicolon (;).&lt;br /&gt;
* The characters '//' are used to indicate comments - there to aid understanding of the program. These are ignored by the compiler.&lt;br /&gt;
* Where variables are defined in the Flowcode program, the prefix 'FCV_' must be added to the name of the variable, which is written in upper case lettering.&lt;br /&gt;
* The 'if-else' construction examines a possible condition - &amp;quot;Is Port A bit 0 high?&amp;quot;&lt;br /&gt;
:* If true, the values of the two variables are added together and sent to Port B.&lt;br /&gt;
:* If false, only the value of 'var1' is sent to Port B.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* All of this could have been done using 'pure' Flowcode, but it would have required around five more icons in the flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
As pointed out earlier, Flowcode will not simulate added C code, and so there is no value in simulating this program.&amp;lt;br /&amp;gt;&lt;br /&gt;
Instead, compile it to the PIC chip which you specified as the target.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following E-Blocks units to the EB-008 Multiprogrammer holding the PIC chip:&lt;br /&gt;
:: a switch unit to Port A,&lt;br /&gt;
:: a LED unit to Port B.&lt;br /&gt;
Press the reset switch on the Multiprogrammer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Test the program by noticing the output displayed on the LEDs when switch 0 on the switch unit is pressed.&lt;br /&gt;
* When pressed, LEDs D2 and D0 should light, indicating an output 0101 (i.e. the number 5,)&lt;br /&gt;
* When not pressed, LED D1 should light, indicating an output 0010, (i.e. the number 2.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Macros&amp;diff=11154</id>
		<title>Exercise - Using Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Macros&amp;diff=11154"/>
		<updated>2013-09-01T13:54:57Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Macros are sections of code that are repeated a number of times within a program.&amp;lt;br /&amp;gt;&lt;br /&gt;
It is more efficient to use a macro than to create the code repeatedly every time it is needed.&amp;lt;br /&amp;gt;&lt;br /&gt;
For more information about macros, see [[What Is a Macro?]].&lt;br /&gt;
&lt;br /&gt;
This exercise shows how to use macros with a menu to create a simple LED flasher. The LED can be made to flash at different frequencies by pressing different switches.&lt;br /&gt;
&lt;br /&gt;
The first section looks at creating the core program, with the menu. The second section shows how to create the macro.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Linking frequency and delay==&lt;br /&gt;
[[File:Exercise_Using_Macros_LED_Flash.png|200px|right]]&lt;br /&gt;
The flowchart controlling the LED flashes is shown opposite.&amp;lt;br /&amp;gt;&lt;br /&gt;
The table that follows shows the link between length of delay in each 'Delay' icon, and the frequency of flashing.&lt;br /&gt;
The LED is switched on for one delay period, and then off for one delay period.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | LED frequency and delay&lt;br /&gt;
|-&lt;br /&gt;
| Delay in milliseconds || Frequency&lt;br /&gt;
|-&lt;br /&gt;
| 1000 ||0.5&lt;br /&gt;
|-&lt;br /&gt;
| 500 ||1&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 250 ||2&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
| 125 ||4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create the variables==&lt;br /&gt;
The program will use two variables, 'selection', to store the state of the switches used to select frequency, and 'delay', used to determine the frequency at which the LED flashes.&lt;br /&gt;
:* In the 'Edit' menu, on the main toolbar, click on 'Variables...' to open the [[Variable Manager]] dialogue box.&lt;br /&gt;
::* Hover just to the left of the 'Variables' label, and click on the down arrow that appears.&lt;br /&gt;
::* Select 'Add new' and the 'Create a New Variable' dialogue box opens.&lt;br /&gt;
::* Name the first new variable &amp;quot;selection&amp;quot;.&lt;br /&gt;
::* Leave the variable type as 'Byte'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* Now do the same thing again to add the second variable &amp;quot;delay&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Create the macro==&lt;br /&gt;
[[File:Exercise_Using_Macros_Set_Frequency_Properties.png|250px|right]]&lt;br /&gt;
* Open the 'Macro' menu on the main toolbar, and click on the 'New...' option.&lt;br /&gt;
: The 'Create a New Macro' dialogue box opens.&lt;br /&gt;
:* Name the new macro &amp;quot;Set_Frequency&amp;quot;. &lt;br /&gt;
:: (Notice the underscore! &lt;br /&gt;
:: Macro names must appear to be a single word. To use more than one word, join them together with underscore characters.)&lt;br /&gt;
:* Hover to the left of the 'Parameters' label, and click on the down arrow that appears.&lt;br /&gt;
:* Click on 'Add new' and then write in the name &amp;quot;delay&amp;quot; as the variable name in the dialogue box that opens.&lt;br /&gt;
:* Leave the 'Description:' box empty, and accept the default variable type, 'Byte'.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
: The dialogue box for this macro is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: Notice that this creates a new tab, called 'Set_Frequency' on the Flowcode work area.&lt;br /&gt;
[[File:Exercise_Using_Macros_Macro_Loop.png|250px|right]]&lt;br /&gt;
:* Click on this tab so that you can create the details of the macro.&lt;br /&gt;
::* Drag and drop a 'Loop' icon between 'BEGIN' and 'END'.&lt;br /&gt;
::* Double click on it to open its dialogue box.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Loop ten times&amp;quot;.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* Tick the 'Loop count:' box and insert the number &amp;quot;10&amp;quot;.&lt;br /&gt;
[[File:Exercise_Using_Macros_Output_Properties.png|250px|right]]&lt;br /&gt;
: The dialogue box for the 'Loop' is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::: Inside the loop:&lt;br /&gt;
::* Drag and drop and 'Output' icon, and double click on it.&lt;br /&gt;
:::* Change the 'Display name:' to &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
:::* Configure it to output value &amp;quot;1&amp;quot; to bit 0 of Port A.&lt;br /&gt;
:::* Click on 'OK'.&lt;br /&gt;
[[File:Exercise_Using_Macros_Macro_Delay.png|250px|right]]&lt;br /&gt;
: This dialogue box for the 'Output' icon is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* Follow this icon with a 'Delay' icon, and double click on it.&lt;br /&gt;
:::* Leave the 'Display name:' as 'Delay', and the timing units as 'milliseconds'.&lt;br /&gt;
:::* In the 'Delay value or variable:' box, type the name of the variable &amp;quot;delay&amp;quot;.&lt;br /&gt;
:::* Click on 'OK'.&lt;br /&gt;
: The dialogue box for this 'Delay' is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* Next, place a second 'Output' icon. &lt;br /&gt;
::: The easiest way to do this is to 'copy and paste' the first one, then select the copy and drag it into position.&lt;br /&gt;
::* Double click on it and rename it &amp;quot;Switch off&amp;quot;.&lt;br /&gt;
:::* Configure it to output value &amp;quot;0&amp;quot; to bit 0 of Port A.&lt;br /&gt;
:::* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* Follow that with a second 'Delay' icon, configured in exactly the same way as the first.&lt;br /&gt;
::: (Again, 'copy and paste' followed by dragging the resulting icon is the easiest way to do this.)&lt;br /&gt;
: The structure of the macro should resemble that shown below.&lt;br /&gt;
[[File:Exercise_Using_Macros_Flowchart_Progress.png|250px|center]]&lt;br /&gt;
&lt;br /&gt;
==The main sequence==&lt;br /&gt;
This part of the program uses three switches to select the frequency for the LED.&amp;lt;br /&amp;gt;&lt;br /&gt;
The flowchart sequence will be:&lt;br /&gt;
::::* Read the state of the switches.&lt;br /&gt;
::::* Use this state to determine the correct branch to take.&lt;br /&gt;
::::* Set up the appropriate time delay for the chosen frequency.&lt;br /&gt;
::::* Run the macro with that delay setting.&lt;br /&gt;
::::* Loop back and check the switches again.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up the 'main' flowchart==&lt;br /&gt;
* Open Flowcode, and set up the new flowchart as described in [[Exercise - Creating a Flowchart|Creating a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Click and drag an infinite loop, [[File:Btn Loop.gif|border]] between the 'BEGIN' and 'END' icons.&lt;br /&gt;
: Inside the loop:&lt;br /&gt;
[[File:Exercise_Using_Macros_Input_Properties.png|250px|right]]&lt;br /&gt;
:* Click and drag an 'Input' icon [[File:Btn Input.gif|border]]. &lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Rename it &amp;quot;Read the switches&amp;quot; and set it up to input from the entire Port B.&lt;br /&gt;
::* In the 'Variable:' box, type &amp;quot;selection&amp;quot;&lt;br /&gt;
::: The three switches will be connected to bits 0, 1 and 2 of Port B.&lt;br /&gt;
::: The state of these switches will be stored in the variable 'selection'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
:: The input dialogue box for the 'Input' icon is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Macros_Switch_Properties.png|250px|right]]&lt;br /&gt;
:* Click and drag a 'Switch-case' icon, [[File:Btn Switch.gif|border]] after the 'Input' icon.&lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Leave the 'Display name:' as 'Switch'.&lt;br /&gt;
::* In the 'Switch:' box, type the name of the variable that will trigger the branching, &amp;quot;selection&amp;quot;.&lt;br /&gt;
::* Tick the first three 'Case:' boxes, and change the content of the third one from '3' to '4'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
:: The 'Switch-case' dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:* Inside each of the three branches ('=1', '=2' and '=3'), click and drag a macro icon, [[File:Btn Macro.gif|border]] and a calculation icon, [[File:Btn Calculation.gif|border]]. &lt;br /&gt;
::* In the '=1' branch, double click on the 'Calculation' icon, and rename it &amp;quot;One hertz delay&amp;quot;.&lt;br /&gt;
::* In the 'Calculations:' box, type &amp;quot;delay = 500&amp;quot;.&lt;br /&gt;
::* In the '=2' branch, double click on the 'Calculation' icon, and rename it &amp;quot;Two hertz delay&amp;quot;.&lt;br /&gt;
::* In the 'Calculations:' box, type &amp;quot;delay = 250&amp;quot;.&lt;br /&gt;
::* In the '=4' branch, double click on the 'Calculation' icon, and rename it &amp;quot;Four hertz delay&amp;quot;.&lt;br /&gt;
::* In the 'Calculations:' box, type &amp;quot;delay = 125&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The three 'Calculation' dialogue boxes are shown below.&lt;br /&gt;
&amp;lt;Gallery widths=120px&amp;gt;&lt;br /&gt;
File:Exercise_Using_Macros_Delay_Properties_01.png&lt;br /&gt;
File:Exercise_Using_Macros_Delay_Properties_02.png&lt;br /&gt;
File:Exercise_Using_Macros_Delay_Properties_04.png&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
[[File:Exercise_Using_Macros_Flash_Macro.png|250px|right]]&lt;br /&gt;
:* Double click on each of the macro icons, in turn, and:&lt;br /&gt;
::* change the 'Display name:' to &amp;quot;Flash macro&amp;quot;;&lt;br /&gt;
::* click on the 'Set_Frequency' label that appears (alone) in the list of possible macros;&lt;br /&gt;
::* type &amp;quot;delay&amp;quot; in the 'Parameters:' 'Expression' box.&lt;br /&gt;
:* Then click on 'OK'.&lt;br /&gt;
:: The resulting dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Main sequence flowchart===&lt;br /&gt;
The final flowchart for the main sequence should resemble the one shown below.&lt;br /&gt;
[[File:Exercise_Using_Macros_Main_Flowchart.png|850px|center]]&lt;br /&gt;
&lt;br /&gt;
==Add the electronics==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Add the switches===&lt;br /&gt;
* Locate the 'Push Round Panel' switch in the 'Inputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the switch label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:: An image of the push-button switch appears on the System Panel.&lt;br /&gt;
:* Click on the image of the switch on the System panel to select it.&lt;br /&gt;
:* Use the 'Edit' menu on the main toolbar to copy and paste two more instances of this push-button switch.&lt;br /&gt;
:* Click on one to select it, and use the Panel Properties to give it coordinates 'X'=-25, 'Y'=10, 'Z'=0.&lt;br /&gt;
:* In the same way, give the second coordinates of 'X'=0, 'Y'=10, 'Z'=0, and the third coordinates of 'X'=25, 'Y'=10, 'Z'=0.&lt;br /&gt;
:* Click on the first again, and then click on the 'Connections' property on the Panel Properties.&lt;br /&gt;
:* Use the microcontroller pinout that appears to connect the switch to Port B, bit 0.&lt;br /&gt;
:* Similarly, connect the other two switches to Port B, bit 1 and Port B, bit 2.&lt;br /&gt;
&lt;br /&gt;
===Add the LED===&lt;br /&gt;
* Locate the 'Single LED' in the 'Outputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the 'Single LED' label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Select the LED on the System panel and drag it to a suitable position below the switches.&lt;br /&gt;
:* Look at the Panel Properties, the 'Connection' property shows that, by default, it is connected to Port A, bit 0.&lt;br /&gt;
:: Leave it like this.&lt;br /&gt;
&lt;br /&gt;
===The System Panel===&lt;br /&gt;
The System Panel should now resemble the one shown below.&lt;br /&gt;
[[File:Exercise_Using_Macros_System_Panel.png|250px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The alternative==&lt;br /&gt;
The final flowchart is much more compact because it uses a macro. The flowchart that follows does the same job, without using a macro:&lt;br /&gt;
[[File:Exercise_Using_Macros_Complete_Flowchart.png|1200px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11153</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11153"/>
		<updated>2013-09-01T13:54:28Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we can stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
* Otherwise, the simulation repeats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* a Simulation macro icon[[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a second loop;&lt;br /&gt;
::* a Calculation icon.&lt;br /&gt;
&lt;br /&gt;
:* Within the second loop, add:&lt;br /&gt;
::* two more Simulation macro icons;&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Simmove.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Set initial position&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveTo' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* set the X value to &amp;quot;200&amp;quot;;&lt;br /&gt;
::::* set the Y value to &amp;quot;0&amp;quot;;&lt;br /&gt;
::::* set the Z value to &amp;quot;28&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second loop:&lt;br /&gt;
:::* set it to 'Loop while:' &amp;quot;hit = 0&amp;quot;;&lt;br /&gt;
:::* 'Test the loop at the:' 'End'&lt;br /&gt;
:::* Click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Moveint.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simcheck.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the third Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the final Calculation icon:&lt;br /&gt;
::::* name it &amp;quot;Reset variables&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;hit = 0&amp;quot; and &amp;quot;xpos = 5.0&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops for three seconds.&lt;br /&gt;
&lt;br /&gt;
: Then the simulation repeats.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation when the lamp is lit, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Component_Macros&amp;diff=11152</id>
		<title>Exercise - Using Component Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Component_Macros&amp;diff=11152"/>
		<updated>2013-09-01T13:53:49Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Component macros are sections of code that have been written to support the components included with Flowcode 6.&amp;lt;br /&amp;gt;&lt;br /&gt;
They take all the effort out of using these components.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This exercise uses them to control a particularly complicated, but very common device, the Liquid Crystal Display (LCD).&amp;lt;br /&amp;gt;&lt;br /&gt;
In this case, it uses a LCD to display elapsed time in a timer.&lt;br /&gt;
&lt;br /&gt;
The first section looks at using [[Component Macro Icon Properties|Component Macros]] to create the core timing sequence. The second section looks at using it to turn on a lamp for ten seconds once a switch is pressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==The core timing sequence==&lt;br /&gt;
At the core of the program is a section that sets up the LCD to display the time.&amp;lt;br /&amp;gt;&lt;br /&gt;
The flowchart sequence for displaying the elapsed time will be:&lt;br /&gt;
::::* Initialize the LCD using the 'Start' macro.&lt;br /&gt;
::::* Set the cursor position in the LCD, using the 'Cursor' macro.&lt;br /&gt;
::::* Display the text &amp;quot;Elapsed time&amp;quot;, using the 'PrintString' macro.&lt;br /&gt;
::::* Set the time to zero.&lt;br /&gt;
::::* Change the cursor position, using the 'Cursor' macro.&lt;br /&gt;
::::* Display the time.&lt;br /&gt;
::::* Wait for one second.&lt;br /&gt;
::::* Increment the time.&lt;br /&gt;
::::* Display the new time.&lt;br /&gt;
::::* Loop back and repeat the process from the one second delay.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up the flowchart===&lt;br /&gt;
* Open Flowcode, and set up the new flowchart as described in [[Exercise - Creating a Flowchart|Creating a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Create the core sequence===&lt;br /&gt;
===Add the LCD===&lt;br /&gt;
* Locate the 'LCD' inside the 'Outputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the 'LCD' label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Zoom in until the LCD image is big enough to read. (See [[Exercise - Controlling the Camera]] for information on how to zoom in on the [[System Panel]].)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Initialise the LCD===&lt;br /&gt;
* Click and drag an infinite loop between the 'BEGIN' and 'END' icons.&lt;br /&gt;
* Inside the loop:&lt;br /&gt;
:* Click and drag a 'Component macro' icon.[[File:Btn_Component_Macro.gif|border]]&lt;br /&gt;
::* Double click on it to open the dialogue box, so that you can configure it.&lt;br /&gt;
::: The program 'knows' which components you have added to the System or Dashboard panel, and modifies the list of available commands accordingly.&lt;br /&gt;
::: Under 'Components', the LCD will be listed, and underneath it the list of commands.&lt;br /&gt;
::* Scroll down to the bottom of the list and click on the 'Start' command.&lt;br /&gt;
::* Rename the 'Display name' as &amp;quot;Start the LCD&amp;quot;.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* The dialogue box is shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Set up the display===&lt;br /&gt;
The first task is to define where the text will be displayed.&amp;lt;br /&amp;gt;&lt;br /&gt;
This involves another LCD 'Component Macro' called 'Cursor'.&lt;br /&gt;
This defines the LCD 'cell' where the text display starts. The LCD has a grid of 32 cells, arranged in 2 rows of 16.&amp;lt;br /&amp;gt;&lt;br /&gt;
The upper row is given the value y=0, and the lower y=1. The sixteen horizontal cells are given values from x=0 to x=15.&lt;br /&gt;
:* Click and drag a second 'Component macro' icon just below the first.&lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Scroll down to the 'Cursor' command.&lt;br /&gt;
::* Rename the 'Display name' as &amp;quot;Move the cursor&amp;quot;.&lt;br /&gt;
::* In the 'Parameters' section, set the value of 'x' to 2, and 'y' to 0.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
The next 'Component Macro' specifies the text to be printed, starting at this location.&lt;br /&gt;
:* Click and drag a third 'Component macro' icon just below the first.&lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Scroll down to the 'PrintString' command and click on it.&lt;br /&gt;
::* Rename the 'Display name' as &amp;quot;Elapsed time&amp;quot;.&lt;br /&gt;
::* In the 'Expression' box, type &amp;quot;Elapsed time&amp;quot; (making sure you include the quotation marks &amp;quot;&amp;quot;.)&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* The dialogue box is shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Component_Macros_Variable_Properties.png|250px|right]]&lt;br /&gt;
===Display elapsed time===&lt;br /&gt;
:* In the 'Edit' menu, on the main toolbar, click on 'Variables...' to open the [[Variable Manager]] dialogue box.&lt;br /&gt;
::* Hover just to the left of the 'Variables' label, and click on the down arrow that appears.&lt;br /&gt;
::* Select 'Add new' and the 'Create a New Variable' dialogue box opens.&lt;br /&gt;
::* Name the new variable &amp;quot;time&amp;quot;, and give it an initial value of zero.&lt;br /&gt;
::* Leave the variable type as 'Byte'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* The dialogue box is shown below.&lt;br /&gt;
&lt;br /&gt;
: The next Component Macro repositions the cursor, so that the elapsed time is shown below the &amp;quot;Elapsed time&amp;quot; label.&amp;lt;br /&amp;gt;&lt;br /&gt;
: The y value is changed to y=1, and the x value to x=8.&lt;br /&gt;
:* Click and drag a fourth 'Component Macro' to follow the third one.&lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Scroll down to the 'Cursor' command.&lt;br /&gt;
::* Rename the 'Display name' as &amp;quot;Move the cursor&amp;quot;.&lt;br /&gt;
::* In the 'Parameters' section, set the value of 'x' to 8, and 'y' to 1.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
:* Click and drag a fifth 'Component macro' icon just below the fourth.&lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Scroll down to the 'PrintNumber' command and click on it.&lt;br /&gt;
::* Rename the 'Display name' as &amp;quot;Display elapsed time&amp;quot;.&lt;br /&gt;
::* In the 'Expression' box, type the variable name &amp;quot;time&amp;quot;.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* The fifth 'Component Macro' dialogue box is shown below.&lt;br /&gt;
&amp;lt;gallery widths=200px heights=200px perrow=5 caption=&amp;quot;Component Macro Properties&amp;quot;&amp;gt;&lt;br /&gt;
File:Exercise_Using_Component_Macros_Icon_Properties_01.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Icon_Properties_04.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Icon_Properties_02.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Icon_Properties_05.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Icon_Properties_03.png&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Finishing touches===&lt;br /&gt;
:* Click and drag a 'Delay' icon to follow the fifth 'Component Macro'.&lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Rename it &amp;quot;Wait one second.&amp;quot;&lt;br /&gt;
::* Configure it to give a delay of one second.&lt;br /&gt;
::: For help with 'Delay' icons, see [[Icon Properties]]&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:* Click and drag a 'Calculation' icon to follow the 'Delay'.&lt;br /&gt;
::* Double click on it to open the dialogue box.&lt;br /&gt;
::* Rename it &amp;quot;Add one second.&amp;quot;&lt;br /&gt;
::* In the 'Calculations:' section, type &amp;quot;time=time+1&amp;quot;.&lt;br /&gt;
::: The effect of this is to increase the number stored in the 'time' variable by one, (also called incrementing the 'time' variable.)&lt;br /&gt;
::: For help with 'Calculation' icons, see [[Icon Properties]]&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
===Test the Core===&lt;br /&gt;
: The diagram below shows the flowchart at this stage.&lt;br /&gt;
[[File:Exercise_Using_Component_Macros_Flowchart_01.png|350px|center]]&lt;br /&gt;
: At this point, the flowchart should be saved as 'Timer', and can be simulated to test it.&lt;br /&gt;
&lt;br /&gt;
==Extend the program==&lt;br /&gt;
The full program is designed to:&lt;br /&gt;
:::: wait until a switch is pressed momentarily;&lt;br /&gt;
:::: light a lamp ;&lt;br /&gt;
:::: time a ten second period;&lt;br /&gt;
:::: then switch it off.&lt;br /&gt;
&lt;br /&gt;
To do this, the sequence is now modified, as follows:&lt;br /&gt;
:* Is the switch pressed?&lt;br /&gt;
::* If not, branch back and test the switch again.&lt;br /&gt;
::* If it has:&lt;br /&gt;
:::* light the lamp;&lt;br /&gt;
:::* run through the timing core ten times,&lt;br /&gt;
:::* switch off the lamp.&lt;br /&gt;
&lt;br /&gt;
===Add the switch===&lt;br /&gt;
* Locate the 'Push Round Panel' switch in the 'Inputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the switch label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Click on the image of the switch on the System panel to select it and drag it to a suitable position.&lt;br /&gt;
:* On the Panel Properties, click on the 'Unconnected' label, next to 'Connection'.&lt;br /&gt;
:: A pinout of the microcontroller appears.&lt;br /&gt;
:* Click on the rectangle that represents the pin RA1/AN1, to connect the switch to Port A, bit 1 of the microcontroller.&lt;br /&gt;
&lt;br /&gt;
===Add the LED===&lt;br /&gt;
* Locate the 'Single LED' in the 'Outputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the 'Single LED' label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Select the LED on the System panel and drag it to a suitable position.&lt;br /&gt;
:* Look at the Panel Properties, the 'Connection' property shows that, by default, it is connected to Port A, bit 0.&lt;br /&gt;
:: Leave it like this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Modify the flowchart===&lt;br /&gt;
* Immediately after the 'Begin' icon, drag and drop a 'Connection Point (Declare Connection Point)' icon.[[File:Btn Connection Point.gif|border]]&lt;br /&gt;
* Next, add an 'Input' icon, and double click on it to open the dialogue box.&lt;br /&gt;
* Change the 'Display name:' to &amp;quot;Read the switch&amp;quot;.&lt;br /&gt;
* Create a new variable, called 'switch'. One way to do this is to click on the down arrow at the end of the 'Variable:' box.&lt;br /&gt;
:* Then click on the down arrow next to the 'Variables' label, and select 'Add new'.&lt;br /&gt;
:* The 'Create a New Variable' dialogue box opens. Type in &amp;quot;switch&amp;quot; as the name of the new variable. Leave the variable type as 'Byte'.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
* In the 'Variable' box, type the name of the new variable &amp;quot;switch&amp;quot;.&lt;br /&gt;
* In the 'Port:' box, select 'PORT A'. Configure the rest of the dialogue box to 'Input from:' 'Single Bit:' 1.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
* Next, drag and drop a 'Decision' box, and double click on it to open the dialogue box.&lt;br /&gt;
:* Rename it &amp;quot;Switch pressed?&amp;quot;.&lt;br /&gt;
:* In the condition 'If' box, type &amp;quot;switch=1&amp;quot;&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
* In the 'No' branch, drag and drop a 'Connection Point (Jump to Connection Point)' icon.[[File:Btn Goto Connection Point.gif|border]]&lt;br /&gt;
* In the 'Yes' branch, drag and drop an 'Output' icon.&lt;br /&gt;
:* Double click on it to open the dialogue box.&lt;br /&gt;
:* Change the 'Display name:' to &amp;quot;Switch on the lamp&amp;quot;.&lt;br /&gt;
:* In the 'Variable or value:' box, type &amp;quot;1&amp;quot;.&lt;br /&gt;
:* Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
* Click and drag the 'Loop' icon to follow this in the 'Yes' branch.&lt;br /&gt;
:* Double click on the 'Loop' icon to configure it.&lt;br /&gt;
:* Leave the 'Display name:' as 'Loop', and the 'Loop while:' box checked.&lt;br /&gt;
:* In the other box, type the condition &amp;quot;time&amp;lt;10&amp;quot;.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
* After the end of the loop, drag and drop a second 'Output' icon.&lt;br /&gt;
:* Double click on it, rename it &amp;quot;Switch off the lamp&amp;quot; and configure it to output value 0 to Port A, bit 0.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The dialogue boxes for all these additions are shown below.&lt;br /&gt;
&amp;lt;gallery widths=200px heights=200px perrow=5 caption=&amp;quot;Added Component Macro Properties&amp;quot;&amp;gt;&lt;br /&gt;
File:Exercise_Using_Component_Macros_Input_Properties_01.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Decision_Properties_01.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Output_Properties_01.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Loop_Properties_01.png&lt;br /&gt;
File:Exercise_Using_Component_Macros_Output_Properties_02.png&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The final flowchart resembles the one below.&lt;br /&gt;
[[File:Exercise_Using_Component_Macros_Flowchart_02.png|350px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Final testing==&lt;br /&gt;
* [[Saving a Flowchart|Save the flowchart]].&lt;br /&gt;
* [[Starting Flowchart Simulation|Run the simulation]] to test that it works.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Expanding_a_Program&amp;diff=11151</id>
		<title>Exercise - Expanding a Program</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Expanding_a_Program&amp;diff=11151"/>
		<updated>2013-09-01T13:53:19Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Taking Flowcode Further&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise assumes you have created, tested and documented the program described in the exercise [[Exercise - Documenting a Flowchart|Documenting a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
Because you have documented the flowchart properly, you can easily and accurately change the program as you know exactly how the program functions and what process it goes through.&lt;br /&gt;
&lt;br /&gt;
You do not have to massively alter your program to make it more effective, sometimes a little change can make a big difference, simply adding and configuring one component can change the program to be much more effective and suitable for use elsewhere.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Load the Flowcode flowchart==&lt;br /&gt;
* [[Opening an Existing Flowchart|Open the flowchart]] called 'Lamp1.fcf' which you created earlier and documented in the exercise [[Exercise - Documenting a Flowchart|Documenting a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Enhancing a program==&lt;br /&gt;
Now that you have a fully functioning program which is properly documented both by display names of icons and detailed comments, you can manipulate this program integrate it into another system, or expand the program further and turn it into your own expanded system, and even turn it into a full application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We are going to expand our program to function as a set of traffic lights, to do this we are going to add 2 more LEDs and add to our 'Decision' icon which responds to when the switch is on to activate the traffic lights accordingly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the LEDs==&lt;br /&gt;
[[File:Exercise_Expanding_a_Program_Components.png|right]]&lt;br /&gt;
First of all, we are going to set up the System Panel and add two more LED components to expand the program.&lt;br /&gt;
* Add two LED components by using either of the following methods:&lt;br /&gt;
:* Either copy and paste the current component on the System Panel to duplicate the component.&lt;br /&gt;
:* Or add two more components by using the [[Tools and Views#2) Components Toolbar|Components Toolbar]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now position the LEDs accordingly on the System Panel.&lt;br /&gt;
* Move the LEDs to be aligned in a row on the Y axis.&lt;br /&gt;
* Ensure the original green LED component is at the bottom and that it is still connected to '$PORTB.0'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next change the colour and connection properties of the two new LEDs.&lt;br /&gt;
* Change the middle LED properties.&lt;br /&gt;
:* Connect the LED to Port B Pin 1 by changing the 'Connection' property to '$PORTB.1'.&lt;br /&gt;
:* Change the 'Color' property to yellow (00FFFF) using the colour selection window.&lt;br /&gt;
&lt;br /&gt;
* Change the top LED properties&lt;br /&gt;
:* Connect the LED to Port B Pin 2 by changing the 'Connection' property to '$PORTB.2'.&lt;br /&gt;
:* Change the 'Color' property to red (000FF) using the colour selection window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expand the program==&lt;br /&gt;
Now that the components are set up correctly, its time to configure the flowchart and expand the program.&lt;br /&gt;
Firstly we need to set up the default state of the traffic lights to display only the red light when the switch is not pressed.&lt;br /&gt;
[[File:Exercise_Expanding_a_Program_Final_Flowchart.png|right]]&lt;br /&gt;
* Add an 'Input' icon to the 'No' section of the 'Decision' icon.&lt;br /&gt;
:* Change the 'Display name:' to &amp;quot;Red on&amp;quot;.&lt;br /&gt;
:* Input the the value &amp;quot;1&amp;quot; into the 'Variable or value:' box.&lt;br /&gt;
:* Set the 'Port:' connection to 'PORTB'.&lt;br /&gt;
:* In the 'Output to:' section select 'Single Bit:' and change the pin to '2'.&lt;br /&gt;
:* Click 'OK' to confirm the changes to the icon.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We are now going to set up the activation sequence of the traffic lights by configuring and expanding the 'Yes' section of the 'Decision' icon.&lt;br /&gt;
&lt;br /&gt;
* Add 4 'Input' icons above the existing icons, then add a 'Delay' icon in-between the 4 'Input' icons.&lt;br /&gt;
:* We will configure these icons top to bottom as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Change the 'Display name:' of the first 'Input' icon to &amp;quot;Red on&amp;quot;.&lt;br /&gt;
:* This icon is the same as the previous one we set up in the 'No' section of the 'Decision icon'.&lt;br /&gt;
:* Send the value '1' to Port B, Pin 2.&lt;br /&gt;
&lt;br /&gt;
* For the second 'Input' icon change the name to &amp;quot;Yellow on&amp;quot;.&lt;br /&gt;
:* Similarly send the value '1' to Port B but this time send it to bit (pin) 1&lt;br /&gt;
&lt;br /&gt;
* Next is the 'Delay' icon.&lt;br /&gt;
:* Change the name to &amp;quot;For 1 second&amp;quot;.&lt;br /&gt;
:* Input the value &amp;quot;1&amp;quot; into the 'Delay value or variable:' box.&lt;br /&gt;
:* Change the unit to 'seconds'.&lt;br /&gt;
&lt;br /&gt;
* Switch the first two (red and yellow) lights off to allow the last (green) light to show on its own which we programmed before.&lt;br /&gt;
:* Alter the 'Input' icon after the 'Delay' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Red off&amp;quot;.&lt;br /&gt;
::* Send the value &amp;quot;0&amp;quot; to Port B, Pin 1 - this switches off the red light.&lt;br /&gt;
:* Configure the next 'Input' icon, the last of the new icons we added.&lt;br /&gt;
::* Name it &amp;quot;Yellow off&amp;quot;.&lt;br /&gt;
::* Send the value &amp;quot;0&amp;quot; to Port B, Pin 2 - this switches off the yellow light.&lt;br /&gt;
&lt;br /&gt;
Next, the green light displays for 10 seconds before switching off, this is due to the icons we configured and programmed in the earlier exercises.&lt;br /&gt;
* Update the display names of the existing icons as follows:&lt;br /&gt;
:* Replace the &amp;quot;Switch on&amp;quot; display name with &amp;quot;Green on&amp;quot;.&lt;br /&gt;
:* Replace the &amp;quot;Switch off&amp;quot; display name with &amp;quot;Green off&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Under these icons add an 'Input' icon, followed by a 'Delay' icon and finally add the last 'Input' icon.&lt;br /&gt;
:* Configure the first 'Input' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Yellow on&amp;quot;.&lt;br /&gt;
::* In the 'Variable or value:' box type &amp;quot;1&amp;quot;.&lt;br /&gt;
::* Change the 'Port:' to 'PORTB'.&lt;br /&gt;
::* In the 'Output to:' section select 'Single Bit:' and change the value to '1'.&lt;br /&gt;
&lt;br /&gt;
:* Now configure the 'Delay' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;For 2 seconds&amp;quot;.&lt;br /&gt;
::* Type &amp;quot;2&amp;quot; into the 'Delay value or variable:'.&lt;br /&gt;
::* Change the unit to 'seconds'&lt;br /&gt;
&lt;br /&gt;
:* Finally configure the last 'Input' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Yellow off&amp;quot;.&lt;br /&gt;
::* In the 'Variable or value:' type &amp;quot;0&amp;quot;.&lt;br /&gt;
::* Change the 'Port:' to 'PORTB'&lt;br /&gt;
::* In the 'Output to:' section select 'Single Bit:' and change it to '1'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Final testing==&lt;br /&gt;
* [[Saving a Flowchart|Save the flowchart]].&lt;br /&gt;
* [[Starting Flowchart Simulation|Run the simulation]] to test that it works.&lt;br /&gt;
* If you are going to further expand a program, or release it for public use, be sure to [[Exercise - Documenting a Flowchart|document the flowchart]] accordingly to explain the process and describe what affect it has on the components.&lt;br /&gt;
&lt;br /&gt;
==What Next?==&lt;br /&gt;
Now you have effectively developed and expanded a program you can move on to other exercises and learn different areas, methods and techniques. &lt;br /&gt;
&lt;br /&gt;
The next exercise available will show you how create an effective program using [[Component Macro Icon Properties|Component Macros]] and how to expand the program using Component Macros to increase efficiency. (See [[Exercise - Using Component Macros]])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Expanding_a_Program&amp;diff=11150</id>
		<title>Exercise - Expanding a Program</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Expanding_a_Program&amp;diff=11150"/>
		<updated>2013-09-01T13:52:49Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Taking Flowcode Further&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise assumes you have created, tested and documented the program described in the exercise [[Exercise - Documenting a Flowchart|Documenting a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
Because you have documented the flowchart properly, you can easily and accurately change the program as you know exactly how the program functions and what process it goes through.&lt;br /&gt;
&lt;br /&gt;
You do not have to massively alter your program to make it more effective, sometimes a little change can make a big difference, simply adding and configuring one component can change the program to be much more effective and suitable for use elsewhere.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Load the Flowcode flowchart==&lt;br /&gt;
* [[Opening an Existing Flowchart|Open the flowchart]] called 'Lamp1.fcf' which you created earlier and documented in the exercise [[Exercise - Documenting a Flowchart|Documenting a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Enhancing a program==&lt;br /&gt;
Now that you have a fully functioning program which is properly documented both by display names of icons and detailed comments, you can manipulate this program integrate it into another system, or expand the program further and turn it into your own expanded system, and even turn it into a full application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We are going to expand our program to function as a set of traffic lights, to do this we are going to add 2 more LEDs and add to our 'Decision' icon which responds to when the switch is on to activate the traffic lights accordingly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the LEDs==&lt;br /&gt;
[[File:Exercise_Expanding_a_Program_Components.png|right]]&lt;br /&gt;
First of all, we are going to set up the System Panel and add two more LED components to expand the program.&lt;br /&gt;
* Add two LED components by using either of the following methods:&lt;br /&gt;
:* Either copy and paste the current component on the System Panel to duplicate the component.&lt;br /&gt;
:* Or add two more components by using the [[Tools and Views#2) Components Toolbar|Components Toolbar]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now position the LEDs accordingly on the System Panel.&lt;br /&gt;
* Move the LEDs to be aligned in a row on the Y axis.&lt;br /&gt;
* Ensure the original green LED component is at the bottom and that it is still connected to '$PORTB.0'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Next change the colour and connection properties of the two new LEDs.&lt;br /&gt;
* Change the middle LED properties.&lt;br /&gt;
:* Connect the LED to Port B Pin 1 by changing the 'Connection' property to '$PORTB.1'.&lt;br /&gt;
:* Change the 'Color' property to yellow (00FFFF) using the colour selection window.&lt;br /&gt;
&lt;br /&gt;
* Change the top LED properties&lt;br /&gt;
:* Connect the LED to Port B Pin 2 by changing the 'Connection' property to '$PORTB.2'.&lt;br /&gt;
:* Change the 'Color' property to red (000FF) using the colour selection window.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Expand the program==&lt;br /&gt;
Now that the components are set up correctly, its time to configure the flowchart and expand the program.&lt;br /&gt;
Firstly we need to set up the default state of the traffic lights to display only the red light when the switch is not pressed.&lt;br /&gt;
[[File:Exercise_Expanding_a_Program_Final_Flowchart.png|right]]&lt;br /&gt;
* Add an 'Input' icon to the 'No' section of the 'Decision' icon.&lt;br /&gt;
:* Change the 'Display name:' to &amp;quot;Red on&amp;quot;.&lt;br /&gt;
:* Input the the value &amp;quot;1&amp;quot; into the 'Variable or value:' box.&lt;br /&gt;
:* Set the 'Port:' connection to 'PORTB'.&lt;br /&gt;
:* In the 'Output to:' section select 'Single Bit:' and change the pin to '2'.&lt;br /&gt;
:* Click 'OK' to confirm the changes to the icon.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We are now going to set up the activation sequence of the traffic lights by configuring and expanding the 'Yes' section of the 'Decision' icon.&lt;br /&gt;
&lt;br /&gt;
* Add 4 'Input' icons above the existing icons, then add a 'Delay' icon in-between the 4 'Input' icons.&lt;br /&gt;
:* We will configure these icons top to bottom as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Change the 'Display name:' of the first 'Input' icon to &amp;quot;Red on&amp;quot;.&lt;br /&gt;
:* This icon is the same as the previous one we set up in the 'No' section of the 'Decision icon'.&lt;br /&gt;
:* Send the value '1' to Port B, Pin 2.&lt;br /&gt;
&lt;br /&gt;
* For the second 'Input' icon change the name to &amp;quot;Yellow on&amp;quot;.&lt;br /&gt;
:* Similarly send the value '1' to Port B but this time send it to bit (pin) 1&lt;br /&gt;
&lt;br /&gt;
* Next is the 'Delay' icon.&lt;br /&gt;
:* Change the name to &amp;quot;For 1 second&amp;quot;.&lt;br /&gt;
:* Input the value &amp;quot;1&amp;quot; into the 'Delay value or variable:' box.&lt;br /&gt;
:* Change the unit to 'seconds'.&lt;br /&gt;
&lt;br /&gt;
* Switch the first two (red and yellow) lights off to allow the last (green) light to show on its own which we programmed before.&lt;br /&gt;
:* Alter the 'Input' icon after the 'Delay' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Red off&amp;quot;.&lt;br /&gt;
::* Send the value &amp;quot;0&amp;quot; to Port B, Pin 1 - this switches off the red light.&lt;br /&gt;
:* Configure the next 'Input' icon, the last of the new icons we added.&lt;br /&gt;
::* Name it &amp;quot;Yellow off&amp;quot;.&lt;br /&gt;
::* Send the value &amp;quot;0&amp;quot; to Port B, Pin 2 - this switches off the yellow light.&lt;br /&gt;
&lt;br /&gt;
Next, the green light displays for 10 seconds before switching off, this is due to the icons we configured and programmed in the earlier exercises.&lt;br /&gt;
* Update the display names of the existing icons as follows:&lt;br /&gt;
:* Replace the &amp;quot;Switch on&amp;quot; display name with &amp;quot;Green on&amp;quot;.&lt;br /&gt;
:* Replace the &amp;quot;Switch off&amp;quot; display name with &amp;quot;Green off&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Under these icons add an 'Input' icon, followed by a 'Delay' icon and finally add the last 'Input' icon.&lt;br /&gt;
:* Configure the first 'Input' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Yellow on&amp;quot;.&lt;br /&gt;
::* In the 'Variable or value:' box type &amp;quot;1&amp;quot;.&lt;br /&gt;
::* Change the 'Port:' to 'PORTB'.&lt;br /&gt;
::* In the 'Output to:' section select 'Single Bit:' and change the value to '1'.&lt;br /&gt;
&lt;br /&gt;
:* Now configure the 'Delay' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;For 2 seconds&amp;quot;.&lt;br /&gt;
::* Type &amp;quot;2&amp;quot; into the 'Delay value or variable:'.&lt;br /&gt;
::* Change the unit to 'seconds'&lt;br /&gt;
&lt;br /&gt;
:* Finally configure the last 'Input' icon.&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Yellow off&amp;quot;.&lt;br /&gt;
::* In the 'Variable or value:' type &amp;quot;0&amp;quot;.&lt;br /&gt;
::* Change the 'Port:' to 'PORTB'&lt;br /&gt;
::* In the 'Output to:' section select 'Single Bit:' and change it to '1'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Final testing==&lt;br /&gt;
* [[Saving a Flowchart|Save the flowchart]].&lt;br /&gt;
* [[Starting Flowchart Simulation|Run the simulation]] to test that it works.&lt;br /&gt;
* If you are going to further expand a program, or release it for public use, be sure to [[Exercise - Documenting a Flowchart|document the flowchart]] accordingly to explain the process and describe what affect it has on the components.&lt;br /&gt;
&lt;br /&gt;
==What Next?==&lt;br /&gt;
Now you have effectively developed and expanded a program you can move on to other exercises and learn different areas, methods and techniques. &lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next exercise available will show you how create an effective program using [[Component Macro Icon Properties|Component Macros]] and how to expand the program using Component Macros to increase efficiency. (See [[Exercise - Using Component Macros]])&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Documenting_a_Flowchart&amp;diff=11149</id>
		<title>Exercise - Documenting a Flowchart</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Documenting_a_Flowchart&amp;diff=11149"/>
		<updated>2013-09-01T13:52:09Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Adding Finishing Touches&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise assumes that you have created and tested the program described in exercise [[Exercise - Transferring a Program to the Microcontroller|Transferring a Program to the Microcontroller]].&lt;br /&gt;
&lt;br /&gt;
Documenting the flowchart is essential in some projects, although we have properly labelled the icons, a few comment icons helps to further explain the program and the process in further detail to aid expansion and helps others understand the system.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Load the Flowcode flowchart==&lt;br /&gt;
* [[Opening an Existing Flowchart|Open the flowchart]] called 'Lamp1.fcf' which you tested further in the exercise [[Exercise - Transferring a Program to the Microcontroller|Transferring a Program to the Microcontroller]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Benefits of documentation==&lt;br /&gt;
&lt;br /&gt;
Documenting your flowchart is very useful - it allows other users to understand your flowchart and allows them to learn and even add to your flowchart to help produce the final program and increase efficiency throughout the system.&lt;br /&gt;
&lt;br /&gt;
Adding comments to document your flowchart is extremely easy and very useful, using comments allows you to clarify the process, purpose and function of your program and allows others to understand it so they can see what is going on and learn from it and even help to develop the program, even by suggestion a more efficient method or directly editing a icon to function more effectively.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Adding comments==&lt;br /&gt;
[[File:Exercise_Documenting_a_Flowchart_Final_Flowchart.png|right]]&lt;br /&gt;
* Drag a [[Comment Icon Properties|Comment icon]] onto the flowchart above the 'Loop' icon.&lt;br /&gt;
* Double click the 'Comment' icon to open up the [[Comment Icon Properties]] dialogue box.&lt;br /&gt;
&lt;br /&gt;
:* Explain the purpose of the loop and how it is the base of the process.&lt;br /&gt;
&lt;br /&gt;
:: The loop is the base of the program as it allows the program to continually check if the switch has been pressed by repeating the process of detecting the state of the switch.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Add a comment above the 'Input' icon.&lt;br /&gt;
&lt;br /&gt;
* Open the icon properties by double clicking on the 'Comment' icon.&lt;br /&gt;
&lt;br /&gt;
:* Describe the use of the 'Input' icon and how it reads the state of the switch.&lt;br /&gt;
&lt;br /&gt;
:: The 'Input' icon uses a variable to read and store the state of the switch, this allows the information contained in the variable to be used to see if the switch is being pressed or not.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Comment and document the 'Decision' icon.&lt;br /&gt;
&lt;br /&gt;
:* Describe how the 'Decision' icon detects the state of the switch and decides the next step to take.&lt;br /&gt;
&lt;br /&gt;
:: The 'Decision' icon will read the information in the variable to see if the switch has been pressed, it then decides which process path to follow next, if it is not being pressed it will go straight through to the loop and continually check if the switch is being pressed or not. If the switch is being pressed the following icons activate the LED and turns it off after 10 seconds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Comment and document the 'Output' icon.&lt;br /&gt;
&lt;br /&gt;
:* Describe the function of the 'Output' icon.&lt;br /&gt;
&lt;br /&gt;
:: Once the 'Decision' icon detects that the switch is being pressed, the 'Output' icon turns on / lights up the LED and indicates that the switch has been pressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Comment and document the 'Delay' icon.&lt;br /&gt;
&lt;br /&gt;
:* Describe the function and purpose of the icon.&lt;br /&gt;
&lt;br /&gt;
:: This delays the program and stops it from continuing with another process, this allows the LED to stay lit up due to the previous command, this delay lasts 10 seconds until the program is then continued.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Comment and document the second 'Output' icon.&lt;br /&gt;
&lt;br /&gt;
:* Explain the function of this icon and the process afterwards.&lt;br /&gt;
&lt;br /&gt;
:: After the 10 second delay, this icon will turn the LED off and then continue the process of the program, which in turn, will loop to check if the button is being pressed again, this is the completes the circuit and will continue to loop and repeat the process, until stopped.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Save the Flowchart==&lt;br /&gt;
* Save the flowchart using the same name. The simplest way to do this is to click on the 'Save' icon. [[File:Btn Save.png|border]]&lt;br /&gt;
: For more information, see [[Saving a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What Next?==&lt;br /&gt;
Now that the flowchart is complete, and documented correctly, you can further expand and develop the flowchart in the next exercise [[Exercise - Expanding a Program|Expanding a Program]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Transferring_a_Program_to_the_Microcontroller&amp;diff=11148</id>
		<title>Exercise - Transferring a Program to the Microcontroller</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Transferring_a_Program_to_the_Microcontroller&amp;diff=11148"/>
		<updated>2013-09-01T13:51:36Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Adding Finishing Touches&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise looks at transferring to the microcontroller, the flowchart 'Lamp1.fcf' which you tested and simulated in the exercise [[Exercise - Simulating a Program|Simulating a Program]].&amp;lt;br /&amp;gt;&lt;br /&gt;
This involves:&lt;br /&gt;
* Compiling the program (translating it into a form which the microcontroller can use).&lt;br /&gt;
* Moving it to the connected microcontroller. &lt;br /&gt;
* Storing it in the microcontroller's memory. &lt;br /&gt;
For more details about this part of the process, see [[Adding Finishing Touches]].&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
==Load the Flowcode Flowchart==&lt;br /&gt;
&lt;br /&gt;
* [[Opening an Existing Flowchart|Open the flowchart]] called 'Lamp1.fcf' which you tested in the exercise [[Exercise - Simulating a Program|Simulating a Program]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Compile the program==&lt;br /&gt;
* Click on the 'Compile to chip' icon. [[File:Btn_Compile_Chip.png|border]]&lt;br /&gt;
: The 'Compiler Messages' box appears and shows the progress of the process.&lt;br /&gt;
: First of all, the program is converted into 'C' language.&lt;br /&gt;
: This is then translated into another language called 'Assembler'.&lt;br /&gt;
: Finally, the resulting code is transferred to the microcontroller.&lt;br /&gt;
: The good news is that all of this happens automatically, without the need for any intervention from you!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What Next?==&lt;br /&gt;
Now you have tested that the program performs on hardware correctly, develop your flowchart further by documenting it for clear interpretation by others and for future expansion purposes as described in the exercise [[Exercise - Documenting a Flowchart]]&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Simulating_a_Program&amp;diff=11147</id>
		<title>Exercise - Simulating a Program</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Simulating_a_Program&amp;diff=11147"/>
		<updated>2013-09-01T13:51:13Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Overview of Simulation&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise looks at testing the flowchart 'Lamp1.fcf' which you developed in the exercise [[Exercise - Adding Devices to a Program|Adding Devices to a Program]].&amp;lt;br /&amp;gt;&lt;br /&gt;
The first part of this process is to simulate the flowchart. This tests the program only, and not the hardware.&lt;br /&gt;
It is done within the Flowcode program itself, and does not require that any hardware is present.&lt;br /&gt;
For more details about simulation, see [[Overview of Simulation]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Load the Flowcode Flowchart==&lt;br /&gt;
&lt;br /&gt;
* [[Opening an Existing Flowchart|Open the flowchart]] you created earlier called 'Lamp1.fcf' which you expanded upon in the exercise [[Exercise - Adding Devices to a Program|Adding Devices to a Program]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Run the simulation==&lt;br /&gt;
* Click on the 'Run' icon, (or hit the F5 function key). [[File:Btn_Run.png|border]]&lt;br /&gt;
: The [[Simulation Debugger|Simulation debugger]] window may open - ignore it for now!&lt;br /&gt;
* Nothing happens until you switch the lamp on. To do this, click momentarily on the push switch.&lt;br /&gt;
: The lamp comes on and the 'Simulation Delay' window opens, as Flowcode simulates the ten second delay.&lt;br /&gt;
: At the end of this, the lamp goes off.&lt;br /&gt;
* You can repeat the process as many times as you like. When you are ready, click on the 'Stop simulation' icon, (or press the Shift and F5 keys). [[File:Btn_Stop.png|border]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Step through the simulation==&lt;br /&gt;
: When things don't go according to plan, it is useful to simulate the program step-by-step, (meaning icon-by-icon.)&lt;br /&gt;
: To do this:&lt;br /&gt;
:* Click on the 'Step Into' icon, (or press the F8 key). [[File:Btn_Step_Into.png|border]]&lt;br /&gt;
:: A red box appears around the first icon in the flowchart. &lt;br /&gt;
:: When you click on the icon again, the program executes that icon, and the red box moves onto the next icon.&lt;br /&gt;
:: In this way, you can check whether or not the expected actions happen. &lt;br /&gt;
* At any point, click on the 'Stop simulation' icon to end the simulation.&lt;br /&gt;
: For more information, see [[Simulating Icons Step by Step]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What Next?==&lt;br /&gt;
Once you have shown that the flowchart does what you want it to, the next step is to transfer the program to the microcontroller, and test that it runs the hardware as you want it to. That is covered in the exercise [[Exercise - Transferring a Program to the Microcontroller|Transferring a Program to the Microcontroller]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Adding_Devices_to_a_Program&amp;diff=11146</id>
		<title>Exercise - Adding Devices to a Program</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Adding_Devices_to_a_Program&amp;diff=11146"/>
		<updated>2013-09-01T13:50:47Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Controlling Electronic Devices With Flowcode&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise assumes that you have already built the Flowcode flowchart described in the exercise [[Exercise - Configuring Icons and Variables|Configuring Icons and Variables]].&amp;lt;br /&amp;gt;&lt;br /&gt;
To complete the program, you need to add the two electronic components, the switch and the lamp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Load the Flowcode Flowchart==&lt;br /&gt;
&lt;br /&gt;
* Open the flowchart, called 'Lamp1.fcf' which you created in the exercise [[Exercise - Configuring Icons and Variables|Configuring Icons and Variables]].&lt;br /&gt;
:(For help with this, see the article [[Opening an Existing Flowchart]]) &lt;br /&gt;
: The System Panel and Panel Properties should be visible. If not, use the [[View]] menu to select them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the Switch==&lt;br /&gt;
[[File:Exercise Adding Devices to a Program Switch Properties.png|300px|right]]&lt;br /&gt;
* Click on the 'Inputs' toolbox, and locate the 'Push Round Panel' [[File:Component Icon 5c1da48f ce54 4622 bdd9 fc812e373696.png]] switch.&lt;br /&gt;
* Hover over the image, and click on the down arrow that appears.&lt;br /&gt;
* Select the 'Add to system panel' option.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Click on the switch on the [[System Panel]] to select it. Its properties appear in the Panel Properties.&lt;br /&gt;
: Notice that the name ('Handle') of the component selected appears at the top of the Panel Properties.&lt;br /&gt;
: In this case, it shows the name of the switch as 'sw_push_rnd_pnl'!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Find the 'Connections' properties on the Panel Properties, the box to the right of it.&lt;br /&gt;
: A pinout of the microcontroller appears. &lt;br /&gt;
:* Ensure that it is connected to Port A bit 0 by using the drop down menus or clicking on the rectangle representing the pin for Port A bit 0 (called RA0/AN0 on the graphic.)&lt;br /&gt;
:: This connects the switch to Port A bit 0 of the microcontroller, matching the settings you used when you created the flowchart.&lt;br /&gt;
:: This setting is shown opposite.&lt;br /&gt;
&lt;br /&gt;
:* No other properties need changing, though '[[Object Scale|Scale]]' allows you to change the size (and shape) of the switch if you wish.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the Lamp==&lt;br /&gt;
[[File:Exercise Adding Devices to a Program LED Properties.png|300px|right]]&lt;br /&gt;
* Click on the 'Outputs' toolbox, and locate the 'Single LED', which we will use as a lamp.&lt;br /&gt;
* Hover over the image, and click on the down arrow that appears.&lt;br /&gt;
* Select the 'Add to system panel' option.&lt;br /&gt;
* The LED appears in the middle of the System Panel, probably right on top of the switch.&lt;br /&gt;
: It should already be selected, but if not click on it.&lt;br /&gt;
: If so, drag it to a suitable position off to one side.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* With the LED selected, look at the Panel Properties.&lt;br /&gt;
: Notice that the 'Handle' has changed to 'led'.&lt;br /&gt;
: The 'Connection' property may not be connected to the correctly, as the flowchart expects it to be connected to Port B, bit 0.&lt;br /&gt;
:* Click on the box next to the 'Connection' property and, as before, a pinout of the chip appears.&lt;br /&gt;
:* Click on the rectangle representing the pin for bit 0 of Port B, shown as RB0/INT or use the drop down menus to connect the component.&lt;br /&gt;
:: The Panel Properties now show that the LED is connected to Port B, bit 0.&lt;br /&gt;
&lt;br /&gt;
:* Once again, no other properties need changing, though 'Scale' and 'Color' settings can be altered to change the size and color of the LED.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Save the Flowchart==&lt;br /&gt;
* Save the flowchart using the same name. The simplest way to do this is to click on the 'Save' icon. [[File:Btn Save.png|border]]&lt;br /&gt;
: For more information, see [[Saving a Flowchart]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What Next?==&lt;br /&gt;
Now that the flowchart is complete, we are ready to test it in simulation, as described in the next exercise [[Exercise - Simulating a Program|Simulating a Program]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Configuring_Icons_and_Variables&amp;diff=11145</id>
		<title>Exercise - Configuring Icons and Variables</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Configuring_Icons_and_Variables&amp;diff=11145"/>
		<updated>2013-09-01T13:50:20Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Controlling Electronic Devices With Flowcode&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
This exercise assumes that you have already built the Flowcode flowchart described in the exercise [[Exercise - Creating a Flowchart|Creating a Flowchart]].&amp;lt;br /&amp;gt;&lt;br /&gt;
To set up and program the flowchart you must configure the icons and variables to create an effective and functioning process.&amp;lt;br /&amp;gt;&lt;br /&gt;
This will prepare the program to interact with components connected to the specific ports.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Load the Flowcode flowchart==&lt;br /&gt;
* Open the flowchart, called 'Lamp1.fcf' which you created in the exercise [[Exercise - Creating a Flowchart|Creating a Flowchart]].&lt;br /&gt;
:(For help with this, see the article [[Opening an Existing Flowchart]]) &lt;br /&gt;
: The System Panel and Panel Properties should be visible. If not, use the [[View]] menu to select them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Program the sequence==&lt;br /&gt;
&lt;br /&gt;
Now that the flowchart icons are correctly set up, we need to program them to carry out the following process:&lt;br /&gt;
:Check if the switch is pressed.&lt;br /&gt;
::If it isn't, go back to the beginning.&lt;br /&gt;
::If it is:&lt;br /&gt;
:::Switch on the lamp;&lt;br /&gt;
:::Wait for 10 seconds;&lt;br /&gt;
:::Switch off the lamp;&lt;br /&gt;
:::Go back to the beginning.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Program the input==&lt;br /&gt;
:* Double click on the [[Input Icon Properties|Input icon]]. &lt;br /&gt;
:: This opens the 'Properties: Input' dialogue box, allowing you to configure the way the program treats information from the switch.&lt;br /&gt;
:: This information will be contained in a variable called 'switch'.&lt;br /&gt;
&lt;br /&gt;
::* Click on the down arrow at the right-hand end of the 'Variable:' box to open the variables dialogue box.&lt;br /&gt;
::* Hover to the left of the 'Variables' label and click on the down arrow that appears.&lt;br /&gt;
::* Click on the 'Add new' option to open the 'Create a New Variable' dialogue box.&lt;br /&gt;
&lt;br /&gt;
::* [[Creating Variables|Create a new variable]] named &amp;quot;switch&amp;quot; with initial value &amp;quot;0&amp;quot; and description &amp;quot;Copies the state of the switch&amp;quot;&lt;br /&gt;
::* Leave the 'Variable type:' as 'Byte'.&lt;br /&gt;
::: (For more information about variables, see [[Creating Variables]] and [[Variable Types]].&lt;br /&gt;
::: (The resulting dialogue box is shown opposite.)&lt;br /&gt;
[[File:Exercise_Configuring_Icons_and_Variables_Input_Properties.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:* Finish configuring the input properties as follows:&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Read the switch&amp;quot;.&lt;br /&gt;
::* In the 'Variable:' box, type the name of the variable you created &amp;quot;switch&amp;quot;.&lt;br /&gt;
::* Leave the 'Port:' as PORT A.&lt;br /&gt;
::* Select to 'Input from:' 'Single Bit' and choose bit 0.&lt;br /&gt;
::: (The resulting dialogue box is shown opposite.)&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Configuring_Icons_and_Variables_New_Variable.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
: Set up like this, the program monitors the state of the switch, which will be connected to bit 0 of Port A of the microcontroller.&lt;br /&gt;
: When the program looks at the input switch if it is pressed, the variable 'switch' contains logic 1. If unpressed, it contains logic 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Check the Switch==&lt;br /&gt;
:* Double click on the [[Decision Icon Properties|Decision icon]] to open the configuration dialogue box, and then: [[File:Exercise_Configuring_Icons_and_Variables_Decision_Properties.png|250px|right]]&lt;br /&gt;
::* Rename it &amp;quot;Switch pressed?&amp;quot;.&lt;br /&gt;
::* In the 'If:' box, type &amp;quot;switch=1&amp;quot;.&lt;br /&gt;
::* Leave the 'Swap Yes and No' box unchecked.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
: This will cause the program to perform what is known as a conditional branch.&lt;br /&gt;
: The subsequent course of the program depends on the outcome of the condition specified in the 'Decision' icon.&lt;br /&gt;
: In this case, it depends on whether or not the variable 'switch' = 1.&lt;br /&gt;
: If it is, the program follows the 'Yes' route. If not, it follows the 'No' route.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Control the Lamp==&lt;br /&gt;
: The 'No' branch is easy to set up. All we want is that the program returns to the beginning (taken care of by the 'Loop' icon.)&lt;br /&gt;
: No further configuration is needed.&lt;br /&gt;
[[File:Exercise_Configuring_Icons_and_Variables_Output_Properties_01.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
:* Double click the [[Output Icon Properties|Output icon]] to open the configuration dialogue box, and then:&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;Switch on&amp;quot;.&lt;br /&gt;
::* In the 'Variable or value:' box, type value &amp;quot;1&amp;quot;.&lt;br /&gt;
::* Change the 'Port:' to PORT B.&lt;br /&gt;
::* Select to 'Output to: 'Single Bit' and choose bit 0.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::: (The resulting dialogue box is shown opposite.)&lt;br /&gt;
&lt;br /&gt;
: The effect of this icon is to send a logic 1 signal (high voltage) to the lamp, connected to Port B, bit 0 of the microcontroller.&lt;br /&gt;
: This turns on the lamp.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: Now, we tackle the requirement that it stays on for ten seconds and then goes off.&lt;br /&gt;
[[File:Exercise_Configuring_Icons_and_Variables_Delay_Properties.png|250px|right]]&lt;br /&gt;
* Drag and drop a [[Delay Icon Properties|Delay icon]] after the 'Output' icon.&lt;br /&gt;
:* Double click on it to open the configuration dialogue box, and then:&lt;br /&gt;
::* Change the 'Display name:' to &amp;quot;For 10 seconds&amp;quot;.&lt;br /&gt;
::* Change the 'Delay value:' to '10'.&lt;br /&gt;
::* Change the unit to 'seconds'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::: (The resulting dialogue box is shown opposite.)&lt;br /&gt;
[[File:Exercise_Configuring_Icons_and_Variables_Output_Properties_02.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: Finally, we need to turn off the lamp, after the ten second delay.&lt;br /&gt;
* Double click on the second 'Output' icon to allow you to configure it.&lt;br /&gt;
:* Rename it &amp;quot;Switch off&amp;quot;, and configure it to deliver value &amp;quot;0&amp;quot; to single bit 0 of Port B.&lt;br /&gt;
:: (The resulting dialogue box is shown opposite.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now [[Saving a Flowchart|save the flowchart]] as &amp;quot;Lamp1.fcf&amp;quot;, and [[Closing Flowcode|close Flowcode]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What next==&lt;br /&gt;
The next step is to add the switch and lamp to the flowchart. This is covered in the exercise [[Exercise - Adding Devices to a Program|Adding Devices to a Program]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Creating_a_Flowchart&amp;diff=11144</id>
		<title>Exercise - Creating a Flowchart</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Creating_a_Flowchart&amp;diff=11144"/>
		<updated>2013-09-01T13:49:48Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Flowcode Flowchart?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
The task is to produce a Flowcode flowchart which will set the base of a program that will, when configured and programmed correctly, light a lamp for ten seconds when a switch is pressed. Note that we will not be configuring the flowchart icons to function in this exercise, we are just setting up the base to be expanded upon.&amp;lt;br /&amp;gt;&lt;br /&gt;
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.&amp;lt;br /&amp;gt;&lt;br /&gt;
The program itself may form part of a bigger program.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Formulate the sequence==&lt;br /&gt;
The flowchart sequence will be:&lt;br /&gt;
: Check if the switch is pressed.&lt;br /&gt;
:: If it isn't, go back to the beginning.&lt;br /&gt;
:: If it is:&lt;br /&gt;
::: Switch on the lamp;&lt;br /&gt;
::: Wait for 10 seconds;&lt;br /&gt;
::: Switch off the lamp;&lt;br /&gt;
::: Go back to the beginning.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up the flowchart==&lt;br /&gt;
[[File:Gen_Startup_Selection.png||250px|right]]&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
* On the Startup screen, click on 'New project'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Gen_Project_Options_Target_SIM.png|right|250px]]&lt;br /&gt;
: The [[Project Options]] dialogue box opens. &lt;br /&gt;
: (Click on the link for a full explanation of all the options available.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Accept the default settings by clicking on 'OK'.&lt;br /&gt;
: An empty flowchart window opens, which may contain other items such as a [[System Panel]], [[Dashboard Panel]], [[Properties Panel]] etc.&lt;br /&gt;
: These can be revealed or hidden using the [[View]] menu.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Set up the flowchart window so that you can see the System Panel and the Properties Panel.&lt;br /&gt;
: The flowchart window should resemble the one shown below (depending on the configuration.)&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Creating_a_Flowchart_Flowcode_Layout.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
: The System Panel and Properties Panel can be moved by clicking and dragging the title bar at the top of each panel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Prepare the input==&lt;br /&gt;
: More information about the icons used in this flowchart can be found in [[Icon Properties]].&lt;br /&gt;
* Drag and drop a [[Loop Icon Properties|Loop icon]] between the BEGIN and END icons.&lt;br /&gt;
: The 'Loop' icon will make the microcontroller repeatedly run through the program, (though the icon can be configured to limit the number of times this happens.)&lt;br /&gt;
&lt;br /&gt;
* Inside the loop, drag and drop an [[Input Icon Properties|Input icon]] from the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* This will be configured later and contain a variable value which will be used to read the state of the switch - to detect if the switch is being pressed..&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Prepare the switch==&lt;br /&gt;
* Drag and drop a [[Decision Icon Properties|Decision icon]] after the 'Input' icon.&lt;br /&gt;
: This icon will be used to make the program perform what is known as a conditional branch when the following icons are configured.&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Creating_a_Flowchart_Icons_Layout.png|right]]&lt;br /&gt;
&lt;br /&gt;
: When the icons are configured and programmed, these icons will be able to continually check if the switch is being pressed or not.&lt;br /&gt;
: In the next step we will be adding icons which will allow us to control what happens if the switch is pressed. Note that the program will not function until the icons are configured and programmed.&lt;br /&gt;
&lt;br /&gt;
: Once programmed - when the switch is pressed it will perform an the action or process and continue to check if it is being pressed again.&lt;br /&gt;
: If the switch is not pressed it will follow the 'No' branch and keep looping to continue to check if the switch has been pressed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Set up the lamp==&lt;br /&gt;
: Next we concentrate on the 'Yes' branch of the 'Decision' icon.&lt;br /&gt;
* Drag and drop an [[Output Icon Properties|Output icon]] in the 'Yes' branch.&lt;br /&gt;
: When programmed, this icon is going to function as a trigger to turn the lamp on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: Next we want the lamp to stay on for ten seconds and then turn off.&lt;br /&gt;
* Drag and drop a [[Delay Icon Properties|Delay icon]] after the 'Output' icon.&lt;br /&gt;
:* This is the icon which will allow us to delay the circuit for a specified period of time.&lt;br /&gt;
:* The delay will last for 10 seconds, in this time the circuit will not be able to carry out any other function until the delay is complete.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:* Drag and drop a second 'Output' icon after the 'Delay' icon.&lt;br /&gt;
: Finally this will be used to turn the lamp off after the ten second delay.&lt;br /&gt;
&lt;br /&gt;
Your flowchart should now be set up to resemble the image to the right. Note that none of the icons are configured yet, so the program will not simulate or function, please see the next exercise to configure the icons so that the program will simulate accordingly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now [[Saving a Flowchart|save the flowchart]] as &amp;quot;Lamp1.fcf&amp;quot;, and [[Closing Flowcode|close Flowcode]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What next==&lt;br /&gt;
The flowchart is now ready to be configured and programmed in order to operate electronic devices (components). The configuration of the flowchart is covered in the exercise [[Exercise - Configuring Icons and Variables|Configuring Icons and Variables]].&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on the following link [[File:xxx|xxx]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Analogue_Input_Devices&amp;diff=11094</id>
		<title>Exercise - Using Analogue Input Devices</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Analogue_Input_Devices&amp;diff=11094"/>
		<updated>2013-08-30T13:59:09Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: Advanced Features&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
The aim of this exercise is to demonstrate the use of analogue input devices within a Flowcode flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Digital inputs are simpler to deal with, as they have a finite range of possible values.&amp;lt;br /&amp;gt;&lt;br /&gt;
For example, a two bit digital input can have one of only four possible values - 00, 01, 10 or 11.&amp;lt;br /&amp;gt;&lt;br /&gt;
Flowcode uses an 'Input' icon [[File:Btn Input.gif|border]] to deal with digital inputs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An analogue input, on the other hand can have any of an infinite number of possible values.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a result, it is more difficult to handle in Flowcode.&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_System_Panel.png|300px|right]]&lt;br /&gt;
A component macro [[File:Btn Component Macro.gif|border]] is used to input data from an analogue sensor.&amp;lt;br /&amp;gt;&lt;br /&gt;
The data is then stored in a variable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Component macros are sections of code that have been written to support the components included with Flowcode 6.&amp;lt;br /&amp;gt;&lt;br /&gt;
They take all the effort out of using these components.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this exercise, a warning lamp lights when the signal from an ADC dial device rises too far.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The flowchart sequence==&lt;br /&gt;
The flowchart will:&lt;br /&gt;
::::* Read the value set on the input device, the ADC dial.&lt;br /&gt;
::::* Compare this with a set value, and:&lt;br /&gt;
::::: if greater than the set value, turn on a lamp;&lt;br /&gt;
::::: if less, then make sure that the lamp is off.&lt;br /&gt;
::::* Loop back to the beginning, and repeat the process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Variable_Manager.png|300px|right]]&lt;br /&gt;
==Create the 'input' variable==&lt;br /&gt;
:* In the 'Edit' menu, on the main toolbar, click on 'Variables...' to open the [[Variable Manager]] dialogue box.&lt;br /&gt;
::* Hover just to the left of the 'Variables' label, and click on the down arrow that appears.&lt;br /&gt;
::* Select 'Add new' and the 'Create a New Variable' dialogue box opens.&lt;br /&gt;
::* Name the new variable &amp;quot;input&amp;quot;.&lt;br /&gt;
::* Leave the variable type as 'Byte'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* The dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create the flowchart==&lt;br /&gt;
* Click and drag an infinite loop, [[File:Btn Loop.gif|border]] between the 'BEGIN' and 'END' icons.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Component_Macro_Properties.png|300px|right]]&lt;br /&gt;
* Inside the loop:&lt;br /&gt;
:* Click and drag a 'Component macro' icon.[[File:Btn_Component_Macro.gif|border]]&lt;br /&gt;
::* Double click on it to open the dialogue box, so that you can configure it.&lt;br /&gt;
::: The program 'knows' which components you have added to the System or Dashboard panel, and modifies the list of available commands accordingly.&lt;br /&gt;
::: Under 'Components', the ADC dial will be listed, and underneath it the list of commands.&lt;br /&gt;
::* Scroll down the list and click on the 'GetByte' command.&lt;br /&gt;
::: This reads the output of the analogue input device - the ADC dial in this case, and stores it in the byte variable called 'input'.&lt;br /&gt;
::* Rename the 'Display name' as &amp;quot;Read the input&amp;quot;.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* Again, the dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Next, drag and drop a 'Decision' box, [[File:Btn Decision.gif|border]] and double click on it to open the dialogue box.&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Decision_Properties.png|300px|right]]&lt;br /&gt;
:* Rename it &amp;quot;Compare it !&amp;quot;&lt;br /&gt;
:* In the condition 'If' box, type &amp;quot;input&amp;gt;128&amp;quot;.&lt;br /&gt;
:: The '128' is totally arbitrary in this program. A byte variable can store any value from 0 to 255, so 128 is roughly half way.&lt;br /&gt;
:: In this case, the program decides whether the value stored in the variable 'input' is greater or smaller than 128, and reacts differently depending on that decision.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
::* Again, the resulting dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Output_Properties_01.png|300px|right]]&lt;br /&gt;
* In the 'Yes' branch, drag and drop an 'Output' icon, [[File:Btn Output.gif|border]].&lt;br /&gt;
:* Double click on it to open the dialogue box.&lt;br /&gt;
:* Change the 'Display name:' to &amp;quot;Switch on the lamp&amp;quot;.&lt;br /&gt;
:* In the 'Variable or value:' box, type &amp;quot;1&amp;quot;.&lt;br /&gt;
:* Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Output_Properties_02.png|300px|right]]&lt;br /&gt;
* In the 'No' branch, drag and drop a second 'Output' icon.&lt;br /&gt;
:* Double click on it to open the dialogue box.&lt;br /&gt;
:* Change the 'Display name:' to &amp;quot;Switch off the lamp&amp;quot;.&lt;br /&gt;
:* In the 'Variable or value:' box, type &amp;quot;0&amp;quot;.&lt;br /&gt;
:* Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
::* Again, the dialogue boxes for the 'Output' icons are shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart should now resemble the one shown below.&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Flowchart.png|300px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the LED==&lt;br /&gt;
* Locate the 'Single LED' in the 'Outputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the 'Single LED' label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Select the LED on the System panel and drag it to a suitable position.&lt;br /&gt;
:* Look at the Panel Properties, the 'Connection' property shows that, by default, it is connected to Port A, bit 0.&lt;br /&gt;
:: Leave it like this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the ADC dial==&lt;br /&gt;
The ADC dial represents a number of input devices.&lt;br /&gt;
* Locate the 'ADC dial' in the 'Inputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Select the ADC dial on the System panel and drag it to a suitable position.&lt;br /&gt;
:* Look at the Panel Properties, and locate the 'Connection' property. Just below it, the 'Channel' property shows that, by default, it is connected to 'AN0' - the first bit of the microcontroller capable of accepting an analogue input. Click on 'AN0' to open a pinout of the microcontroller.&lt;br /&gt;
::* Click on the rectangle representing input 'AN1' to change the connection to this channel.&lt;br /&gt;
:: Leave it like this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown at the top of the page.&lt;br /&gt;
&lt;br /&gt;
==Final testing==&lt;br /&gt;
* Save the flowchart as 'Analogue,fcf'.&lt;br /&gt;
* Click on the simulation button [[File:Btn Run.png|border]].&lt;br /&gt;
* Use the mouse to turn the pointer on the ADC dial, and notice what happens when you pass the half-way mark.&lt;br /&gt;
* Click on the 'Stop simulation' button, [[File:Btn Stop.png|border]] when you are happy with the program's behavior.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on this link [[File:Exercise AnInputs Analogue input1.fcf|Analogue Input 1]]&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Analogue_Input_Devices&amp;diff=11086</id>
		<title>Exercise - Using Analogue Input Devices</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Analogue_Input_Devices&amp;diff=11086"/>
		<updated>2013-08-30T13:55:14Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Component?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
The aim of this exercise is to demonstrate the use of analogue input devices within a Flowcode flowchart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Digital inputs are simpler to deal with, as they have a finite range of possible values.&amp;lt;br /&amp;gt;&lt;br /&gt;
For example, a two bit digital input can have one of only four possible values - 00, 01, 10 or 11.&amp;lt;br /&amp;gt;&lt;br /&gt;
Flowcode uses an 'Input' icon [[File:Btn Input.gif|border]] to deal with digital inputs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An analogue input, on the other hand can have any of an infinite number of possible values.&amp;lt;br /&amp;gt;&lt;br /&gt;
As a result, it is more difficult to handle in Flowcode.&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_System_Panel.png|300px|right]]&lt;br /&gt;
A component macro [[File:Btn Component Macro.gif|border]] is used to input data from an analogue sensor.&amp;lt;br /&amp;gt;&lt;br /&gt;
The data is then stored in a variable.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Component macros are sections of code that have been written to support the components included with Flowcode 6.&amp;lt;br /&amp;gt;&lt;br /&gt;
They take all the effort out of using these components.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this exercise, a warning lamp lights when the signal from an ADC dial device rises too far.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The flowchart sequence==&lt;br /&gt;
The flowchart will:&lt;br /&gt;
::::* Read the value set on the input device, the ADC dial.&lt;br /&gt;
::::* Compare this with a set value, and:&lt;br /&gt;
::::: if greater than the set value, turn on a lamp;&lt;br /&gt;
::::: if less, then make sure that the lamp is off.&lt;br /&gt;
::::* Loop back to the beginning, and repeat the process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Variable_Manager.png|300px|right]]&lt;br /&gt;
==Create the 'input' variable==&lt;br /&gt;
:* In the 'Edit' menu, on the main toolbar, click on 'Variables...' to open the [[Variable Manager]] dialogue box.&lt;br /&gt;
::* Hover just to the left of the 'Variables' label, and click on the down arrow that appears.&lt;br /&gt;
::* Select 'Add new' and the 'Create a New Variable' dialogue box opens.&lt;br /&gt;
::* Name the new variable &amp;quot;input&amp;quot;.&lt;br /&gt;
::* Leave the variable type as 'Byte'.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* The dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Create the flowchart==&lt;br /&gt;
* Click and drag an infinite loop, [[File:Btn Loop.gif|border]] between the 'BEGIN' and 'END' icons.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Component_Macro_Properties.png|300px|right]]&lt;br /&gt;
* Inside the loop:&lt;br /&gt;
:* Click and drag a 'Component macro' icon.[[File:Btn_Component_Macro.gif|border]]&lt;br /&gt;
::* Double click on it to open the dialogue box, so that you can configure it.&lt;br /&gt;
::: The program 'knows' which components you have added to the System or Dashboard panel, and modifies the list of available commands accordingly.&lt;br /&gt;
::: Under 'Components', the ADC dial will be listed, and underneath it the list of commands.&lt;br /&gt;
::* Scroll down the list and click on the 'GetByte' command.&lt;br /&gt;
::: This reads the output of the analogue input device - the ADC dial in this case, and stores it in the byte variable called 'input'.&lt;br /&gt;
::* Rename the 'Display name' as &amp;quot;Read the input&amp;quot;.&lt;br /&gt;
::* Click on 'OK'.&lt;br /&gt;
::* Again, the dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Next, drag and drop a 'Decision' box, [[File:Btn Decision.gif|border]] and double click on it to open the dialogue box.&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Decision_Properties.png|300px|right]]&lt;br /&gt;
:* Rename it &amp;quot;Compare it !&amp;quot;&lt;br /&gt;
:* In the condition 'If' box, type &amp;quot;input&amp;gt;128&amp;quot;.&lt;br /&gt;
:: The '128' is totally arbitrary in this program. A byte variable can store any value from 0 to 255, so 128 is roughly half way.&lt;br /&gt;
:: In this case, the program decides whether the value stored in the variable 'input' is greater or smaller than 128, and reacts differently depending on that decision.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
::* Again, the resulting dialogue box is shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Output_Properties_01.png|300px|right]]&lt;br /&gt;
* In the 'Yes' branch, drag and drop an 'Output' icon, [[File:Btn Output.gif|border]].&lt;br /&gt;
:* Double click on it to open the dialogue box.&lt;br /&gt;
:* Change the 'Display name:' to &amp;quot;Switch on the lamp&amp;quot;.&lt;br /&gt;
:* In the 'Variable or value:' box, type &amp;quot;1&amp;quot;.&lt;br /&gt;
:* Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Output_Properties_02.png|300px|right]]&lt;br /&gt;
* In the 'No' branch, drag and drop a second 'Output' icon.&lt;br /&gt;
:* Double click on it to open the dialogue box.&lt;br /&gt;
:* Change the 'Display name:' to &amp;quot;Switch off the lamp&amp;quot;.&lt;br /&gt;
:* In the 'Variable or value:' box, type &amp;quot;0&amp;quot;.&lt;br /&gt;
:* Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.&lt;br /&gt;
:* Click on 'OK'.&lt;br /&gt;
::* Again, the dialogue boxes for the 'Output' icons are shown opposite.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart should now resemble the one shown below.&lt;br /&gt;
[[File:Exercise_Using_Analogue_Input_Devices_Flowchart.png|300px|center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the LED==&lt;br /&gt;
* Locate the 'Single LED' in the 'Outputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the 'Single LED' label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Select the LED on the System panel and drag it to a suitable position.&lt;br /&gt;
:* Look at the Panel Properties, the 'Connection' property shows that, by default, it is connected to Port A, bit 0.&lt;br /&gt;
:: Leave it like this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Add the ADC dial==&lt;br /&gt;
The ADC dial represents a number of input devices.&lt;br /&gt;
* Locate the 'ADC dial' in the 'Inputs' toolbox in the [[Tools and Views#1) Icons Toolbar|Icons toolbar]].&lt;br /&gt;
:* Hover over the image to the left of the label, and click on the down-arrow that appears.&lt;br /&gt;
:* Click on the 'Add to system panel' option to select it.&lt;br /&gt;
:* Select the ADC dial on the System panel and drag it to a suitable position.&lt;br /&gt;
:* Look at the Panel Properties, and locate the 'Connection' property. Just below it, the 'Channel' property shows that, by default, it is connected to 'AN0' - the first bit of the microcontroller capable of accepting an analogue input. Click on 'AN0' to open a pinout of the microcontroller.&lt;br /&gt;
::* Click on the rectangle representing input 'AN1' to change the connection to this channel.&lt;br /&gt;
:: Leave it like this.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown at the top of the page.&lt;br /&gt;
&lt;br /&gt;
==Final testing==&lt;br /&gt;
* Save the flowchart as 'Analogue,fcf'.&lt;br /&gt;
* Click on the simulation button [[File:Btn Run.png|border]].&lt;br /&gt;
* Use the mouse to turn the pointer on the ADC dial, and notice what happens when you pass the half-way mark.&lt;br /&gt;
* Click on the 'Stop simulation' button, [[File:Btn Stop.png|border]] when you are happy with the program's behavior.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Link==&lt;br /&gt;
To download the Flowcode program for this exercise, click on this link [[File:Exercise_AnInput_&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11078</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11078"/>
		<updated>2013-08-30T13:30:58Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we can stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
* Otherwise, the simulation repeats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* a Simulation macro icon[[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a second loop;&lt;br /&gt;
::* a Calculation icon.&lt;br /&gt;
&lt;br /&gt;
:* Within the second loop, add:&lt;br /&gt;
::* two more Simulation macro icons;&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Simmove.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Set initial position&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveTo' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* set the X value to &amp;quot;200&amp;quot;;&lt;br /&gt;
::::* set the Y value to &amp;quot;0&amp;quot;;&lt;br /&gt;
::::* set the Z value to &amp;quot;28&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second loop:&lt;br /&gt;
:::* set it to 'Loop while:' &amp;quot;hit = 0&amp;quot;;&lt;br /&gt;
:::* 'Test the loop at the:' 'End'&lt;br /&gt;
:::* Click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Moveint.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simcheck.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the third Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the final Calculation icon:&lt;br /&gt;
::::* name it &amp;quot;Reset variables&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;hit = 0&amp;quot; and &amp;quot;xpos = 5.0&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops for three seconds.&lt;br /&gt;
&lt;br /&gt;
: Then the simulation repeats.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation when the lamp is lit, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11077</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11077"/>
		<updated>2013-08-30T13:30:00Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* a Simulation macro icon[[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a second loop;&lt;br /&gt;
::* a Calculation icon.&lt;br /&gt;
&lt;br /&gt;
:* Within the second loop, add:&lt;br /&gt;
::* two more Simulation macro icons;&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Simmove.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Set initial position&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveTo' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* set the X value to &amp;quot;200&amp;quot;;&lt;br /&gt;
::::* set the Y value to &amp;quot;0&amp;quot;;&lt;br /&gt;
::::* set the Z value to &amp;quot;28&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second loop:&lt;br /&gt;
:::* set it to 'Loop while:' &amp;quot;hit = 0&amp;quot;;&lt;br /&gt;
:::* 'Test the loop at the:' 'End'&lt;br /&gt;
:::* Click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Moveint.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simcheck.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the third Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the final Calculation icon:&lt;br /&gt;
::::* name it &amp;quot;Reset variables&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;hit = 0&amp;quot; and &amp;quot;xpos = 5.0&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops for three seconds.&lt;br /&gt;
&lt;br /&gt;
: Then the simulation repeats.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation when the lamp is lit, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Moveint.png&amp;diff=11071</id>
		<title>File:Exercise SimIcon Moveint.png</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Moveint.png&amp;diff=11071"/>
		<updated>2013-08-30T13:17:02Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11070</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11070"/>
		<updated>2013-08-30T13:15:22Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* a Simulation macro icon[[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a second loop.&lt;br /&gt;
:* Within the second loop, add:&lt;br /&gt;
::* two more Simulation macro icons;&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Simmove.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Set initial position&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveTo' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* set the X value to &amp;quot;200&amp;quot;;&lt;br /&gt;
::::* set the Y value to &amp;quot;0&amp;quot;;&lt;br /&gt;
::::* set the Z value to &amp;quot;28&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simcheck.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the third Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simmoveint.png&amp;diff=11069</id>
		<title>File:Exercise SimIcon Simmoveint.png</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simmoveint.png&amp;diff=11069"/>
		<updated>2013-08-30T13:14:15Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11063</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11063"/>
		<updated>2013-08-30T13:11:26Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* a Simulation macro icon[[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a second loop.&lt;br /&gt;
:* Within the second loop, add:&lt;br /&gt;
::* two more Simulation macro icons;&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Simmove.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Set initial position&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveTo' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* set the X value to &amp;quot;200&amp;quot;;&lt;br /&gt;
::::* set the Y value to &amp;quot;0&amp;quot;;&lt;br /&gt;
::::* set the Z value to &amp;quot;28&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simmoveint.png|right|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simcheck.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the third Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simcheck.png&amp;diff=11057</id>
		<title>File:Exercise SimIcon Simcheck.png</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simcheck.png&amp;diff=11057"/>
		<updated>2013-08-30T13:05:48Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11051</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11051"/>
		<updated>2013-08-30T13:01:30Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* a Simulation macro icon[[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a second loop.&lt;br /&gt;
:* Within the second loop, add:&lt;br /&gt;
::* two more Simulation macro icons;&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise_SimIcon_Simmove.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Set initial position&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveTo' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* set the X value to &amp;quot;200&amp;quot;;&lt;br /&gt;
::::* set the Y value to &amp;quot;0&amp;quot;;&lt;br /&gt;
::::* set the Z value to &amp;quot;28&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|400px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|250px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the third Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simmove.png&amp;diff=11044</id>
		<title>File:Exercise SimIcon Simmove.png</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simmove.png&amp;diff=11044"/>
		<updated>2013-08-30T12:41:57Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11040</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11040"/>
		<updated>2013-08-30T12:32:18Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* a Simulation macro icon;&lt;br /&gt;
::* a second loop.&lt;br /&gt;
:* Within the second loop, add:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Set initial position&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveTo' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* set the X value to &amp;quot;200&amp;quot;;&lt;br /&gt;
::::* set the Y value to &amp;quot;0&amp;quot;;&lt;br /&gt;
::::* set the Z value to &amp;quot;28&amp;quot;;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the third Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11039</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11039"/>
		<updated>2013-08-30T12:24:40Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
'''The plan:'''&lt;br /&gt;
* Set the initial position of the intruder, using the 'MoveTo' simulation macro.&lt;br /&gt;
&lt;br /&gt;
* Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
* When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Implementation:'''&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11038</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11038"/>
		<updated>2013-08-30T12:21:30Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses three of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan:&lt;br /&gt;
&lt;br /&gt;
: Set the initial position of the intruder, using the 'MoveTo' simulation macro&lt;br /&gt;
: Move the intruder towards the detection cone using the 'MoveAlong' simulation macro. &lt;br /&gt;
:: This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
: When the intruder enters the detection zone, the simulation macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
:: At this point, we stop any more movement so that we can look at the x coordinate of the intruder. &lt;br /&gt;
:: To do so, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11032</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11032"/>
		<updated>2013-08-30T12:17:33Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11030</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11030"/>
		<updated>2013-08-30T12:15:19Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simflow.png&amp;diff=11029</id>
		<title>File:Exercise SimIcon Simflow.png</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=File:Exercise_SimIcon_Simflow.png&amp;diff=11029"/>
		<updated>2013-08-30T12:13:05Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11027</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=11027"/>
		<updated>2013-08-30T11:04:12Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simflow.png|center|500px]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10979</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10979"/>
		<updated>2013-08-30T08:58:27Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;sidebar&amp;gt;Sidebar: What Is a Macro?&amp;lt;/sidebar&amp;gt;&lt;br /&gt;
Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|border]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simprog.png|center|500px]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==DON'T DOWNLOAD IT!!==&lt;br /&gt;
The important point is that the two Simulation macros do not compile to code that can be downloaded to a microcontroller. They affect only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10712</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10712"/>
		<updated>2013-08-26T16:35:24Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuring the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simprog.png|center|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Downloading the program==&lt;br /&gt;
&lt;br /&gt;
* Click on the 'Compile to chip' icon, to download the program to the microcontroller.&lt;br /&gt;
&lt;br /&gt;
* Run the program on the hardware. Nothing happens.&lt;br /&gt;
: The software is waiting for the value of the variable 'hit' to change to logic 1. However, there is no hardware attached to make this happen.&lt;br /&gt;
: There are two remedies:&lt;br /&gt;
::* Add a PIR sensor to the hardware, and connect it to Port A, bit 0.&lt;br /&gt;
::* Use a switch, connected to Port A, bit 0 to mimic the action of the PIR sensor.&lt;br /&gt;
&lt;br /&gt;
: The important point is that the two Simulation macros did not compile to any code that was downloaded to the microcontroller. They affected only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10711</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10711"/>
		<updated>2013-08-26T16:34:56Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Simprog.png|center|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Downloading the program==&lt;br /&gt;
&lt;br /&gt;
* Click on the 'Compile to chip' icon, to download the program to the microcontroller.&lt;br /&gt;
&lt;br /&gt;
* Run the program on the hardware. Nothing happens.&lt;br /&gt;
: The software is waiting for the value of the variable 'hit' to change to logic 1. However, there is no hardware attached to make this happen.&lt;br /&gt;
: There are two remedies:&lt;br /&gt;
::* Add a PIR sensor to the hardware, and connect it to Port A, bit 0.&lt;br /&gt;
::* Use a switch, connected to Port A, bit 0 to mimic the action of the PIR sensor.&lt;br /&gt;
&lt;br /&gt;
: The important point is that the two Simulation macros did not compile to any code that was downloaded to the microcontroller. They affected only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10708</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10708"/>
		<updated>2013-08-26T15:38:31Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'Yes' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
::::* send value '1' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
::::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* In the 'No' loop:&lt;br /&gt;
::::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
::::* send value '0' to Port A single bit 0;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
::::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
::::* configure it to give a delay of 100ms;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Flowcode flowchart resembles the one shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
* Run the simulation.&lt;br /&gt;
: The intruder should move towards the house, until he enters the detection zone. &lt;br /&gt;
&lt;br /&gt;
: At this point, the warning lamp turns on and he stops.&lt;br /&gt;
&lt;br /&gt;
* Stop the simulation, and click on the image of the intruder. You can now read the x coordinate from the Panel properties box.&lt;br /&gt;
&lt;br /&gt;
* Change the height of the PIR sensor on the wall, or the angle of the detection cone, and see what happens to this coordinate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Downloading the program==&lt;br /&gt;
&lt;br /&gt;
* Click on the 'Compile to chip' icon, to download the program to the microcontroller.&lt;br /&gt;
&lt;br /&gt;
* Run the program on the hardware. Nothing happens.&lt;br /&gt;
: The software is waiting for the value of the variable 'hit' to change to logic 1. However, there is no hardware attached to make this happen.&lt;br /&gt;
: There are two remedies:&lt;br /&gt;
::* Add a PIR sensor to the hardware, and connect it to Port A, bit 0.&lt;br /&gt;
::* Use a switch, connected to Port A, bit 0 to mimic the action of the PIR sensor.&lt;br /&gt;
&lt;br /&gt;
: The important point is that the two Simulation macros did not compile to any code that was downloaded to the microcontroller. They affected only the simulation of the program.&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10707</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10707"/>
		<updated>2013-08-26T15:23:07Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder '''by an amount specified by the variable 'xpos''''. &lt;br /&gt;
&lt;br /&gt;
When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. &lt;br /&gt;
&lt;br /&gt;
At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'Yes' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
:::* send value '1' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
:::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'No' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
:::* send value '0' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10706</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10706"/>
		<updated>2013-08-26T15:19:17Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
This exercise allows us to investigate factors such as the height of the sensor on the brick wall and the angle of the detection zone, so that these can be optimised for a typical intruder height.&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder by an amount specified by the variable 'xpos'. When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder. To do this, we change the value of 'xpos' to zero.&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'Yes' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
:::* send value '1' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
:::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'No' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
:::* send value '0' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10705</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10705"/>
		<updated>2013-08-26T15:16:00Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
The plan is to move the intruder towards the detection cone using the 'MoveAlong' macro. This '''changes''' the x coordinate of the intruder by an amount specified by the variable 'xpos'. When the intruder enters the detection zone, the macro 'CollisionTest' returns a value of '1' in the variable 'hit'. At that point, we want to stop any more movement so that we can look at the x coordinate of the intruder.&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'Yes' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
:::* send value '1' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
:::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'No' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
:::* send value '0' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10704</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10704"/>
		<updated>2013-08-26T15:11:33Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'Yes' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch on lamp&amp;quot;;&lt;br /&gt;
:::* send value '1' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Calculation icon &amp;quot;Stop movement&amp;quot;;&lt;br /&gt;
:::* in the 'Calculations:' box, insert &amp;quot;xpos = 0&amp;quot; to reduce the distance incremented each time to zero;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* In the 'No' loop:&lt;br /&gt;
:::* name the Output icon &amp;quot;Switch off lamp&amp;quot;;&lt;br /&gt;
:::* send value '0' to Port A single bit 0;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
:::* name the Delay icon &amp;quot;Wait 100ms&amp;quot;;&lt;br /&gt;
:::* configure it to give a delay of 100ms;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10703</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10703"/>
		<updated>2013-08-26T15:03:53Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Move the intruder&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* name it &amp;quot;Check detection&amp;quot;;&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
:::* name it &amp;quot;Intruder detected?&amp;quot;;&lt;br /&gt;
:::* insert the condition &amp;quot;hit = 1&amp;quot;;&lt;br /&gt;
:::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10702</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10702"/>
		<updated>2013-08-26T14:59:46Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as red;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10701</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10701"/>
		<updated>2013-08-26T14:58:54Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon, [[File:Gen Panel Object Collision Move Around.png|35px]]    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as yellow;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10700</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10700"/>
		<updated>2013-08-26T14:55:07Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
Click on the 'Collisions' icon    and select the 'Move through' option, which allows the intruder to enter the detection cone.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as yellow;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10699</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10699"/>
		<updated>2013-08-26T14:53:09Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (Passive Infra-Red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented in the image by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as yellow;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
	<entry>
		<id>https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10698</id>
		<title>Exercise - Using Simulation Macros</title>
		<link rel="alternate" type="text/html" href="https://www.flowcode.co.uk/wiki/index.php?title=Exercise_-_Using_Simulation_Macros&amp;diff=10698"/>
		<updated>2013-08-25T14:32:41Z</updated>

		<summary type="html">&lt;p&gt;JohnVerrill: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Simulation macros are a form of Component macros. Their purpose is to make simulation more realistic by adding physical components to the electronic devices.&lt;br /&gt;
&lt;br /&gt;
When the Flowcode program is compiled and downloaded to a microcontroller, they are ignored - hence the name Simulation macros. &lt;br /&gt;
&lt;br /&gt;
Even a cursory glance at the dialogue box used to configure them shows that they are very powerful devices, with a huge range of possible effects.&lt;br /&gt;
&lt;br /&gt;
This exercise uses two of them to illustrate the use of a PIR (passive infra-red sensor) to operate an intruder sensor.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The scenario==&lt;br /&gt;
&lt;br /&gt;
The scene depicts the front of a house. &lt;br /&gt;
[[File:Exercise SimIcon pan.png|center|350px]]&lt;br /&gt;
&lt;br /&gt;
A PIR sensor is mounted on the wall of the house, above the path leading across the garden.&lt;br /&gt;
&lt;br /&gt;
The data sheet for the PIR shows that it is sensitive to a range of 10 metres, within a cone of angle 100 degrees.&lt;br /&gt;
&lt;br /&gt;
Its detection area is represented by the pale blue cone.&lt;br /&gt;
&lt;br /&gt;
When an intruder enters the detection cone, a warning lamp lights up in the house.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The System Panel==&lt;br /&gt;
&lt;br /&gt;
On the System Panel, viewed from above (the default position,)create:&lt;br /&gt;
* '''a brick wall''', represented by adding a red cuboid and changing it to a rectangle, 15mm wide, 120mm high and 120mm deep, &lt;br /&gt;
:: located at coordinates x = 0, y = 0, z = 60, &lt;br /&gt;
:: with rotation settings X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a path''', represented by a grey rectangle, 240mm wide, 100mm high and 0mm deep, &lt;br /&gt;
:: located at coordinatesx = 125mm, y = 0mm, z = 0mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = 0, Z = 0;&lt;br /&gt;
&lt;br /&gt;
* '''a cone''', couloured light blue, representing the sensing region of the PIR, with width = 70mm, height = 250mm, depth 95mm, &lt;br /&gt;
:: located at coordinates x = 45mm, y = 0mm, z = 80mm, &lt;br /&gt;
:: with rotation settings of X = 0, Y = -55, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over these three elements and group them together. &lt;br /&gt;
&lt;br /&gt;
This produces 'group 1'. &lt;br /&gt;
:: Give this group:&lt;br /&gt;
::: dimensions - width = 265mm, height = 250mm, depth = 135mm;&lt;br /&gt;
::: coordinates - x = 128, y = 0, z = 68;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Also on the System Panel, create an intruder, by:&lt;br /&gt;
* adding four spheres, and configuruing the properties as follows:&lt;br /&gt;
:: sphere 1 ('''the head'''):&lt;br /&gt;
::: colour pink;&lt;br /&gt;
::: dimensions - width = 12mm, height = 13mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.7, z = 22;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
:: sphere 2 ('''the body'''):&lt;br /&gt;
::: colour blue;&lt;br /&gt;
::: dimensions - width = 14mm, height = 26mm, depth = 24mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 0.5, z = 4;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 3 ('''the legs'''):&lt;br /&gt;
::: colour dark green;&lt;br /&gt;
::: dimensions - width = 9mm, height = 23mm, depth = 15mm;&lt;br /&gt;
::: coordinates - x = -2.2, y = 1, z = -16;&lt;br /&gt;
::: rotation - X = 90, Y = 0, Z = -180.&lt;br /&gt;
&lt;br /&gt;
:: sphere 4 ('''the feet'''):&lt;br /&gt;
::: colour black;&lt;br /&gt;
::: dimensions - width = 6mm, height = 15mm, depth = 25mm;&lt;br /&gt;
::: coordinates - x = -6, y = 0, z = -25;&lt;br /&gt;
::: rotation - X = 90, Y = 90, Z = 0.&lt;br /&gt;
&lt;br /&gt;
* Drag the mouse cursor over the four spheres and group them together.&lt;br /&gt;
&lt;br /&gt;
This produces 'group 2'. &lt;br /&gt;
:: Give it:&lt;br /&gt;
::: dimensions - width = 18mm, height = 32mm, depth = 60mm;&lt;br /&gt;
::: coordinates - x = 165, y = 0, z = 28;&lt;br /&gt;
::: rotation - X = 0, Y = 0, Z = 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The System Panel should resemble the image shown above. (The image has been rotated to show all components. The table-top is coloured green.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Dashboard Panel==&lt;br /&gt;
[[File:Exercise SimIcon dash.png|right|200px]]&lt;br /&gt;
* Open the 'Outputs' toolbox, and locate the 'LED 5mm Panel' device.&lt;br /&gt;
* Click on the down arrow next to it and choose the 'Add to dashboard panel' option.&lt;br /&gt;
* Zoom in to the Dashboard Panel to make the LED large enough to see.&lt;br /&gt;
* Click on the LED and configure its properties as follows:&lt;br /&gt;
::* choose a suitable colour, such as yellow;&lt;br /&gt;
::* connect it to Port A, bit 0.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The Flowcode program==&lt;br /&gt;
&lt;br /&gt;
* [[Opening Flowcode|Open Flowcode]].&lt;br /&gt;
&lt;br /&gt;
* On the Startup screen, click on 'New project' to [[Creating Flowcharts|create a new flowchart]].&lt;br /&gt;
&lt;br /&gt;
* Add the icons shown in the flowchart:&lt;br /&gt;
:* a loop icon, configured as an infinite loop, and within it:&lt;br /&gt;
::* two Simulation macro icons [[File:Btn Simulation Macro.gif|35px]];&lt;br /&gt;
[[File:Exercise SimIcon Sim move.png|right|450px]]&lt;br /&gt;
::* a decision icon with:&lt;br /&gt;
:::* a 'Yes' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
:::* a 'No' loop containing an output icon, followed by a delay icon and then a calculation icon;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Configure the icons, by double clicking on each in turn, as follows:&lt;br /&gt;
::* the top Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Position' folder;&lt;br /&gt;
:::* click on the 'MoveAlong' macro and:&lt;br /&gt;
::::* choose 'group2'(the intruder)as the Handle;&lt;br /&gt;
::::* choose 'shape1'( the brick wall) as the Axis;&lt;br /&gt;
::::* click on the down arrow on the end of the 'X' row, and create a floating point variable called &amp;quot;xpos&amp;quot;, with an initial value 5.0, to use as the X variable;&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim test.png|right|300px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the second Simulation macro:&lt;br /&gt;
:::* click on the 'Panel' tab, and then on the 'Collision' folder;&lt;br /&gt;
:::* click on the 'TestSingle' macro and:&lt;br /&gt;
::::* choose 'shape2'(the detection cone) for 'Pos' and 'shape5' (the intruder's head,) for 'Test';&lt;br /&gt;
:::* use the down arrow at the end of the 'Return Value' box to create a boolean variable caled &amp;quot;hit&amp;quot; to use as the 'Return Value'.&lt;br /&gt;
::::* click on OK.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
::* the decision icon:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Exercise SimIcon Sim prog.png|right|350px]]&lt;br /&gt;
&lt;br /&gt;
* Flowcode &lt;br /&gt;
&lt;br /&gt;
* Experienced &lt;br /&gt;
&lt;br /&gt;
* Students &lt;br /&gt;
&lt;br /&gt;
==Adding supplementary code==&lt;br /&gt;
&lt;br /&gt;
This feature &lt;br /&gt;
&lt;br /&gt;
'''Definitions and function declarations:'''&lt;br /&gt;
&lt;br /&gt;
This is &lt;br /&gt;
 &lt;br /&gt;
'''Function implementations:'''&lt;/div&gt;</summary>
		<author><name>JohnVerrill</name></author>
		
	</entry>
</feed>