Countdown
Description
This object is being used to count down from a time defined in seconds. For example if your time port is set to 10 and you start the object it will count down from 10 to 9 to 8 and so on, one every second. See more examples down below.
The objects will now stop running once input parameters are changed.
App Builder Object
Source Code
function execute() {
switch (trigger) {
case TRIGGERS.SYSTEM_ASYNC:
{
if (context.counter > 0 && context.state) {
context.counter -= 1;
if (context.counter <= 0) {
cancelSleep();
return [null, 0, new Date()];
}
sleep(1000, true);
return [null, context.counter, null];
}
break;
}
case 0:
{
cancelSleep();
context.timer = inPorts[1].value;
context.state = true;
context.counter = context.timer;
sleep(1000, true);
return [new Date(), context.counter, null];
}
case 2: // reset
{
context.state = false;
cancelSleep();
context.counter = 0;
return [null, null, null];
}
default: break;
}
return [];
}
Examples
Example | Initialize | Input Number | Output Number | Time Stamp Start | Time Stamp Ended |
---|---|---|---|---|---|
1 | Trigger | 10 | 10,9,8,7,6,5,4, 3,2,1,0 | 04:35:20 PM | 4:35:30 PM |
2 | Trigger | 4 | 4,3,2,1,0 | 10:06:56 AM | 10:07:00 AM |
In Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Start | Trigger | This port is being used to trigger the 'Countdown' object. |
2 | Time | Number | This port is being used to receive a start number for the ‘Countdown’. |
3 | Reset | Trigger | This port is being used to reset the 'Countdown' object. |
Out Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Started | Trigger | This port is being used to trigger the “Started” time stamp for the 'Countdown'. |
2 | Time | Number | This port is being used to display the counted down number from the 'Countdown'. |
3 | Ended | Trigger | This port is being used to trigger the “Ended“ time stamp for the 'Countdown'. |
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 |