Rotary Counter
Description
This object is being used to count between two numbers from a given value and trigger the over- or underflow.
App Builder Object
Source Code
function execute() {
if (context.min === undefined) {
context.min = parseInt(inPorts[3].value, 10);
}
if (context.max === undefined) {
context.max = parseInt(inPorts[4].value, 10);
}
if (context.value === undefined) {
context.value = parseInt(inPorts[2].value, 10) || context.min;
}
switch (trigger) {
case 0:
if (context.value < context.max && context.value >= context.min) {
context.value += 1;
return [context.value, null, null];
}
context.value = context.min;
return [context.value, new Date(), null];
case 1:
if (context.value > context.min && context.value <= context.max) {
context.value -= 1;
return [context.value, null, null];
}
context.value = context.max;
return [context.value, null, new Date()];
case 2:
if (inPorts[2].value < context.min) {
context.value = context.min;
} else if (inPorts[2].value > context.max) {
context.value = context.max;
} else {
context.value = inPorts[2].value;
}
editInPort(2, {});
return [context.value, null, null];
case 3:
context.min = inPorts[3].value;
break;
case 4:
context.max = inPorts[4].value;
break;
default: break;
}
return [];
}
Examples
Value(Start) | Min | Max | Step | Overflow | Underflow |
---|---|---|---|---|---|
0 | 0 | 3 | 0 | 0 | 0 |
0 | 0 | 3 | 1 | 0 | 0 |
0 | 0 | 3 | 2 | 0 | 0 |
0 | 0 | 3 | 3 | 0 | 0 |
0 | 0 | 3 | 0 | 1 | 0 |
In Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Increment | Trigger | This port is being used to trigger the increment of the 'Rotary Counter'. |
2 | Decrement | Trigger | This port is being used to trigger the decrement of the 'Rotary Counter'. |
3 | Value | Number | This port is being used to get a starting number for the 'Rotary Counter'. |
4 | Min | Number | This port is being used to get the lower limit for the 'Rotary Counter'. |
5 | Max | Number | This port is being used to get the upper limit for the 'Rotary Counter'. |
Out Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Value | Number | This port is being used to receive the current number of the 'Rotary Counter'. |
2 | Overflow | Trigger | This port is being used to trigger the “Overflow“ time stamp for the 'Rotary Counter'. |
3 | Underflow | Trigger | This port is being used to trigger the “Underflow“ time stamp for the 'Rotary Counter'. |
Properties
Name | Description |
---|---|
Object Name | The name on the object on the canvas. |
Show Code View | The switch to turn on code view for the Code Object |
Duplicate Code into custom Code Object |