Watch The Video Tutorial

Let us design a simple light chaser project with 4 LEDs connected to PORTB.0 to PORTB.3 as in the figure below:

NOTE: The power supply is not shown here, the PIC should be connected to +5V(VDD) and Ground (VSS).

As the internal oscillator is not used here, connect an external crystal oscillator on pin 13 and 14 as shown in Reading Switches With PIC Microcontroller.

What is a variable?
In simple terms, a variable is a location in memory where we can store information.
The type of variable created must match the correct type of information that has to be stored in, if we want to store a number, we cannot store it in a location destined to store strings (characters).
Flowcode allows you to create 8 types of variables:

  1. Bool: range: 0 to 1, size: 1-bit unsigned variable (unsigned means of positive value only) this can be used to store information that requires 2 possibilities only like True or false.
  2. Byte: range: 0 to 255, size: 8-bits, this is the default variable and can be used for numbers in that range.
  3. Int: range: +/- 32768, size: 16-bits signed variable (signed means the value can be either positive or negative).
  4. UInt: range: 0 to 65535, size: 16-bits Unsigned variable.
  5. Long: range: +/- 21474836648, size: 32-bits signed variable.
  6. ULong: range: 0 to 4294967295 unsigned variable.
  7. String: range: 0 to 255, size: 8-bit unsigned array. This can be used for characters. The default size of the array is 20 but can be increased as needed.
  8. Floating point: range: from -infinity to + infinity, size: 32-bit. This can be used for floating point numbers (numbers with commas).

Start a new project as learned in the Flowcode v5 Overview and Connecting Light Emitting Diodes to a PIC Microcontroller articles, select the PIC 16F877A. Go to the component toolbar and select 4 LEDs and change their colours to red, green, yellow and blue








As seen from this illustration (1 to 6), all you need is to drag and drop the calculation icon inside the Start and End chart. Double click it to open its property, click on the small arrow then click on “Add new”. Choose your variable type and then give your variable a name.

Important Notes:

  1. When naming  a variable in flowcode note that variables can be a maximum of 32 alphanumeric characters.
    They can contain underscore ( _ ) characters but not spaces. At least one letter must be included in the   variable name to distinguish it from a pure number.
  2. Note that variable names “retain” their capitalization, but Flowcode itself it not case sensitive. 
    If a variable is created as “MyVariable”, then it will be shown as “MyVariable” throughout the document.
    Note that the variable name is changed to “FCV_MYVARIABLE” in the actual C code, as c code is case sensitive.
  3. When you create a new variable you can specify its initial value if you want to. Numeric values can be in decimal (unmarked) or in HEX format (preceded by 0x) or in Binary format (preceded by 0b) e.g. 32 or 0x20 or 0b100000.
  4. Arrays can be created by adding an array size attribute in square braces to the variable  name: E.g. MY_VARIABLE[5] creates an array called MY_VARIABLE with 5 members in the array. You can also set the value of an array member in a calculation icon by using the array name with the member number in square braces. E.g.MY_VARIABLE[2] = 5.
  5. The only difference between an array of bytes and a string is that the string variable is available for use with the Flowcode string manipulation functions. In C code the two are identical.
  6.  Strings are arrays of BYTE ASCII character values. String arrays are composed of the array name and an array element variable. MyChar[20] for instance is an array called MyChar that is 20 characters in size.

Let us continue with our project…

–> Drag and drop a while (1) loop icon after the calculation icon.
–> Drag and drop an Output icon inside the loop and double click it to open its properties.

—> Select PORTB in the Port drop down box.

—> Instead of putting a value in the “Variable or value” drop down box, click the drop down arrow and double click on the desired variable to select it.
—> Insert a delay and continue with the rest of the Output for the rest of the LEDs as in figure below.

Download Variables Flowcode Project