Difference between revisions of "Exercise - Using Analogue Input Devices"

From Flowcode Help
Jump to navigationJump to search
Line 1: Line 1:
The aim of this exercise is to use analogue input devices within a Flowcode flowchart.
+
The aim of this exercise is to demonstrate the use of analogue input devices within a Flowcode flowchart.
  
 
Digital inputs are simpler to deal with, as they have a finite range of possible values.<br />
 
Digital inputs are simpler to deal with, as they have a finite range of possible values.<br />
Line 8: Line 8:
 
As a result, it is more difficult to handle in Flowcode.
 
As a result, it is more difficult to handle in Flowcode.
 
A component macro [[File:Btn Component Macro.gif|30px]] is used to input data from an analogue sensor.
 
A component macro [[File:Btn Component Macro.gif|30px]] is used to input data from an analogue sensor.
 +
The data is then stored in a variable.
  
 
Component macros are sections of code that have been written to support the components included with Flowcode 6.<br />
 
Component macros are sections of code that have been written to support the components included with Flowcode 6.<br />
 
They take all the effort out of using these components.
 
They take all the effort out of using these components.
  
The first section looks at using '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.
 
  
  
 
__TOC__
 
__TOC__
  
==The core timing sequence==
+
 
At the core of the program is a section that sets up the LCD to display the time.<br />
+
==The flowchart sequence==
The flowchart sequence for displaying the elapsed time will be:
+
The flowchart will:
::::* Initialize the LCD using the 'Start' macro.
+
::::* Read the value set on the input device, the ADC dial.
::::* Set the cursor position in the LCD, using the 'Cursor' macro.
+
::::* Compare this with a set value, and:
::::* Display the text "Elapsed time", using the 'PrintString' macro.
+
::::: if greater than the set value, turn on a lamp;
::::* Set the time to zero.
+
::::: if less, then make sure that the lamp is off.
::::* Change the cursor position, using the 'Cursor' macro.
+
::::* Loop back to the beginning, and repeat the process.
::::* Display the time.
 
::::* Wait for one second.
 
::::* Increment the time.
 
::::* Display the new time.
 
  
 
===Create the 'input' variable===
 
===Create the 'input' variable===
Line 40: Line 36:
  
  
 +
===Create the flowchart===
 
* Click and drag an infinite loop between the 'BEGIN' and 'END' icons.
 
* Click and drag an infinite loop between the 'BEGIN' and 'END' icons.
 
* Inside the loop:
 
* Inside the loop:
Line 54: Line 51:
  
 
* Next, drag and drop a 'Decision' box, and double click on it to open the dialogue box.
 
* Next, drag and drop a 'Decision' box, and double click on it to open the dialogue box.
:* Rename it "Switch pressed?".
+
:* Rename it "Compare it !"
:* In the condition 'If' box, type "switch=1"
+
:* In the condition 'If' box, type "input>128".
 +
:: 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.
 
:* Click on 'OK'.
 
:* Click on 'OK'.
* In the 'No' branch, drag and drop a 'Connection Point (Jump to Connection Point)' icon.[[File:Btn Goto Connection Point.gif|30px]]
+
 
 
* In the 'Yes' branch, drag and drop an 'Output' icon.
 
* In the 'Yes' branch, drag and drop an 'Output' icon.
 
:* Double click on it to open the dialogue box.
 
:* Double click on it to open the dialogue box.
Line 65: Line 63:
 
:* Click on 'OK'.
 
:* Click on 'OK'.
  
 +
* In the 'No' branch, drag and drop an 'Output' icon.
 +
:* Double click on it to open the dialogue box.
 +
:* Change the 'Display name:' to "Switch off the lamp".
 +
:* In the 'Variable or value:' box, type "0".
 +
:* Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.
 +
:* Click on 'OK'.
  
 
===Add the LED===
 
===Add the LED===

Revision as of 19:56, 24 June 2013

The aim of this exercise is to demonstrate the use of analogue input devices within a Flowcode flowchart.

Digital inputs are simpler to deal with, as they have a finite range of possible values.
For example, a two bit digital input can have one of only four possible values - 00, 01, 10 or 11.
Flowcode uses an 'Input' icon Btn Input.gif to deal with digital inputs.

An analogue input, on the other hand can have any of an infinite number of possible values.
As a result, it is more difficult to handle in Flowcode. A component macro Btn Component Macro.gif is used to input data from an analogue sensor. The data is then stored in a variable.

Component macros are sections of code that have been written to support the components included with Flowcode 6.
They take all the effort out of using these components.



The flowchart sequence

The flowchart will:

  • Read the value set on the input device, the ADC dial.
  • Compare this with a set value, and:
if greater than the set value, turn on a lamp;
if less, then make sure that the lamp is off.
  • Loop back to the beginning, and repeat the process.

Create the 'input' variable

  • In the 'Edit' menu, on the main toolbar, click on 'Variables...' to open the Variable Manager dialogue box.
  • Hover just to the left of the 'Variables' label, and click on the down arrow that appears.
  • Select 'Add new' and the 'Create a New Variable' dialogue box opens.
  • Name the new variable "input".
  • Leave the variable type as 'Byte'.
  • Click on 'OK'.
  • The dialogue box is shown below.


Create the flowchart

  • Click and drag an infinite loop between the 'BEGIN' and 'END' icons.
  • Inside the loop:
  • Click and drag a 'Component macro' icon.Btn Component Macro.gif
  • Double click on it to open the dialogue box, so that you can configure it.
The program 'knows' which components you have added to the System or Dashboard panel, and modifies the list of available commands accordingly.
Under 'Components', the ADC dial will be listed, and underneath it the list of commands.
  • Scroll down the list and click on the 'GetByte' command.
This reads the output of the analogue input device - the ADC dial in this case, and stores it in the byte variable 'input'.
  • Rename the 'Display name' as "Read the input".
  • Click on 'OK'.
  • The dialogue box is shown below.


  • Next, drag and drop a 'Decision' box, and double click on it to open the dialogue box.
  • Rename it "Compare it !"
  • In the condition 'If' box, type "input>128".
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.
  • Click on 'OK'.
  • In the 'Yes' branch, drag and drop an 'Output' icon.
  • Double click on it to open the dialogue box.
  • Change the 'Display name:' to "Switch on the lamp".
  • In the 'Variable or value:' box, type "1".
  • Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.
  • Click on 'OK'.
  • In the 'No' branch, drag and drop an 'Output' icon.
  • Double click on it to open the dialogue box.
  • Change the 'Display name:' to "Switch off the lamp".
  • In the 'Variable or value:' box, type "0".
  • Configure the rest of the box to output this to 'PORT A' 'Single Bit:' 0.
  • Click on 'OK'.

Add the LED

  • Locate the 'Single LED' in the 'Outputs' toolbox in the Icons toolbar.
  • Hover over the image to the left of the 'Single LED' label, and click on the down-arrow that appears.
  • Click on the 'Add to system panel' option to select it.
  • Select the LED on the System panel and drag it to a suitable position.
  • Look at the Panel Properties, the 'Connection' property shows that, by default, it is connected to Port A, bit 0.
Leave it like this.