Device Functions

Here we will cover a few functions available within your code, these functions

Function

Description

Zen

Plus

get_rtime

Returns the elapsed time between main iterations in milliseconds

✔️

✔️

get_slot

Returns the active slot number

✔️

✔️

load_slot

Loads a specified slot

✔️

✔️

get_ctrlbutton

Returns the identifier of the controller button

✔️

✔️

vm_tctrl

Sets the vm timeout for the next iteration

✔️

✔️

set_polar

Sets the stick output at a given angle and radius with a high resolution value

✔️

set_rgb

Sets the LED on the ZEN to the supplied RGB color

✔️

set_hsb

Sets the LED on the ZEN to the supplied HSB color

✔️

get_rtime

get_rtimereturns the elapsed time between the current and previous iteration of the main function. The value returned is in milliseconds.

You can see this function in action by using this counter script:

int days;
int hours;
int minutes;
int seconds;
int milliseconds;
main {
milliseconds = milliseconds + get_rtime();
if(milliseconds >= 1000) {
milliseconds = milliseconds - 1000
seconds = seconds + 1;
if(seconds == 60) {
seconds = 0;
minutes = minutes + 1;
if(minutes == 60) {
minutes = 0;
hours = hours + 1;
if(hours == 24) {
hours = 0;
days = days + 1;
}
}
}
}
set_val(TRACE_1, days);
set_val(TRACE_2, hours);
set_val(TRACE_3, minutes);
set_val(TRACE_4, seconds);
set_val(TRACE_5, milliseconds / 10);
}

🔴 Syntax

get_rtime ( );

Parameters

None

🔵 Returns

The elapsed time, in milliseconds, between the main iteration

get_slot

get_slot returns an int value representing the current active slot of the Cronus Device.

int _currentSlot;
init {
_currentSlot = get_slot();
}
main {
}

🔴 Syntax

getslot();

Parameters

None

🔵 Returns

An int value representing the current active slot of the Cronus Device.

load_slot

load_slot will attempt to load the slot number specified within its parameter. If there is no script current stored in the specified slot, then it will unload the current slot and load slot 0 of the device.

main {
if(event_press(XB1_RB)) // if RB / R2 is pressed...
load_slot(5); // Load slot 5
if(event_press(XB1_LB)) // if LB / L2 is pressed...
load_slot(0); // Unload current slot and load slot 0
}

🔴 Syntax

load_slot ( <slot_number> );

Parameters

<slot_number> : A value which represents a slot number to load with a range of 0 - 9 on Cronus MAX Plus or 0 - 8 on Cronus ZEN.

🔵 Returns

Nothing

get_ctrlbutton

get_ctrlbutton returns the current control button. The control button is set in the Device tab within Cronus PRO's Options window or the Device Tab of the Cronus Zen. The enable remote control switch on device dictates which button it is set to

{{IMAGE PLACEHOLDER}}

get_ctrlbutton();

🔴 Syntax

get_ctrlbutton( );

Parameters

Nothing

🔵 Returns

Depending on the remote slot settings the value can be 0, 1 or 8.

vm_tctrl

opcode sets the virtual machine timeout for the next iteration. By default, the virtual machine runs the main loop every 10 milliseconds as it aids stability. You can however adjust how often each main iteration is run. Just be aware than changing this setting may cause instability within your script.

main {
vm_tctrl(-5); // Run the VM every 5ms
}

🔴 Syntax

vm_tctrl( <variable> );

Parameters

<variable> : Numeric value to add to the Virtual Machine base time. Range -9 ~ 10

🔵 Returns

Nothing

set_polar

opcode sets one bit of a variable based on its bit index¹ ² ³

opcode(a,5);

🔴 Syntax¹ ² ³

opcode( <variable> , <bit_index> );

Parameters

<variable> : any defined variable. <bit_index> : index point of the bit to be set with a range of 0 to 15.

🔵 Returns

Nothing

set_rgb

opcode sets one bit of a variable based on its bit index¹ ² ³

opcode(a,5);

🔴 Syntax¹ ² ³

opcode( <variable> , <bit_index> );

Parameters

<variable> : any defined variable. <bit_index> : index point of the bit to be set with a range of 0 to 15.

🔵 Returns

Nothing

set_hsb

opcode sets one bit of a variable based on its bit index¹ ² ³

opcode(a,5);

🔴 Syntax¹ ² ³

opcode( <variable> , <bit_index> );

Parameters

<variable> : any defined variable. <bit_index> : index point of the bit to be set with a range of 0 to 15.

🔵 Returns

Nothing