Using Masks

From Flowcode Help
Jump to navigationJump to search

<sidebar>Sidebar: Taking Flowcode Further</sidebar> Before looking at the operation of icons you will need to understand how 'masks' are used within Flowcode. You may wish to come back to this screen once you have looked at how Input and Output icons work.


Masks can be used to select specific number of bits on a port to read from, or write to. Masks can be used with both Input icons and Output icons.


Masks are particularly useful when the same port has both input pins and output pins as they facilitate the control/reading of two or more bits at the same time.


Using masks with Input icons

Bits selected in a mask allow their corresponding value to be sent to the variable. Non-selected bits return zero

Gen Using Masks Input.png

Examples:

If all five switches on Port A were pressed with the above mask only the values for A1 and A2 would be passed to the variable SWITCHES giving it the value of 6, rather than the value 31 which the five switches add up to.


If switch A3 was pressed then the value zero would be passed to the variable SWITCHES as A3 is not selected.


Using masks with Output icons

Bits selected in a mask are passed the value of the corresponding bit of the number or variable sent. Bits that are not selected are not affected and retain their prior value.

Gen Using Masks Output.png

Examples:

If SWITCHES is equal to 255 and is sent with the mask above then bits B0, B1 and B2 will be affected. The other bits B3 - B7 will not be affected, and will retain whatever Bit value they have before the output message. Bits B0 - B2 will be set as the corresponding bits of SWITCHES are set.


If SWITCHES is equal to 32 then bits B0 to B2 will be cleared as the corresponding values for the B0 to B2 are all 0. Bit B5, which corresponds to the value 32 is not affected as it is not selected.


Video instructions

See the Inputs Outputs video for a brief overview and demonstration of masking bits and ports using the Input icon and Output icon.

{{#ev:youtube|uC3jj1ebAFI|640}}