Building an example that processes both inputs and outputs

In this example, we will see how to check whether input values have changed, and then set output values accordingly.

To build an example that processes both inputs and outputs

  1. Add a NION to the design page.
  2. Add a Live Python block to the design page with 2 inputs and 8 outputs.
  3. Add two buttons to the design page, then wire them to the inputs on the Live Python block.

  4. Add 8 text box generic controls to the design page, then wire them to the outputs on the Live Python block.

  5. Emulate the project.
  6. Double-click the Edit button to open the Python source code editor.
  7. Type the following Python code in the editor:

    colors = ['red','green', 'blue','pink','orange','gray','purple','magenta']

    if inputs[0].changed_get():

        for i in range(len(outputs)):

            outputs[i].string_set(colors[i])

    else:

        for i in range(len(outputs)):

            outputs[i].string_set(" ")

  8. Click the first button to see the colors from the array displayed in the yellow text boxes.

  9. Click the second button to clear the values in the text boxes.

In this section

Using alternative Python statements in the example

How different button types affect code execution

See also

Introduction

Building a simple Python example in NWare

Changing Python code while a project is running

Debugging Python scripts

An example with multiple input devices