The Data widget outputs elements from a user define text or numeric database. Each time the input rises above the threshold, the widget outputs the next element in the sequence, in either standard order, reverse order, or random order.
Connect the trigger input to the first inlet. When the value from this input enters the trigger range, an element from the database will be output.
2 Configure the database
In the widget, select Text Data or Numeric Data to define what kind of data will be output.
Open the more section at the bottom of the widget to define your data:
Text – Enter the text you want for the database in the large field under Text. Each element should be separated by a comma by default. If you want to use a different delimiter, change it in the delimiter field. If you want each line of text on a different line, use “n” for the delimiter.
Numeric – The widget works with a range of numbers. The default range is 0-1023, but you can set the minimum and maximum of the range to your preference.
3 Set the order of the data
The widget output data elements in a sequence, one element each time the input enters the trigger range. You can select the element sequence order with the following settings in the widget, where the elements will be output in:
- ordered – original order
- reverse – reverse order
- randFull – a random order with no repeats until all the elements have been output
- randNoRep – a random order with no adjacent repeats
- ranAny – a completely random order where there may be repeats
Once you’ve set the order type, you can see the order at bottom of the widget more section where it says Ordered Database. Each time you change the order, or update the actual data, this field will update to show you how the data will be used.
You can also test the output of the widget by clicking on the section of the widget that displays something like “0 of 7”. Each click will output the next element in the sequence.
4 Set the Trigger Input Settings
By default, the widget will behave like many other widgets, and output a new database element when the input rises above 512. But if you have different needs, you can configure the Data widget to respond in a more detailed way.
Set a specific range
As an example example, if you want a new element to be output when the input from a proximity sensor is in a specific range, say 20 – 30 inches, you can set the trigger up to respond with a new element when the input goes from below 20 into that range, and when it goes from above 30 into that range. Just set the min and max to 20 and 30 respectively.
Set multiple triggers within a range
It’s also possible to define a range, and then have the widget output a new database element as the input rises or lowers throughout that range. For example, using a proximity sensor again, you could set up a range from 1 to 200 inches, and set the number of segments for the trigger range to 4. With this setup, as a person gets closer and closer, a new element will be triggered at 200, 150, 100, and at 50.
5 Get a specific element
The second input of the Data widget causes the widget to output the element that corresponds to that numeric input value. If it is 5, then the element at that position will be output. For example, using the default fruit database (apple, banana, cherry, date, elderberry, fig, grape, huckleberry), an input of 2 would output cherry.
This patch has two examples in it. The top one shows how to use the Data widget to generate varied responses to a single input. The second, bottom example shows how to use two different inputs to select specific elements within the Data widget, using the second input.