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:

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.

Byte:range: 0 to 255, size: 8-bits, this is the default variable and can be used for numbers in that range.

Int:range: +/- 32768, size: 16-bits signed variable (signed means the value can be either positive or negative).

UInt: range: 0 to 65535, size: 16-bits Unsigned variable.

Long: range: +/- 21474836648, size: 32-bits signed variable.

ULong: range: 0 to 4294967295 unsigned variable.

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.

Floating point: range: from -infinity to + infinity, size: 32-bit. This can be used for floating point numbers (numbers with commas).

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:

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.

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.

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.

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.

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.

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.

Stay Update:

Search Here

Translate Website into your Language

Please support our work with a Donation

Writing tutorials and recording tutorials videos requires a lot of resources and time. If you found these tutorials helpful, please show your support and donate any amount you wish so that we can do even more.
Thanks