---
title: Device Functions
slug: gpc/device-functions
description: Explore the code functions within this document, including get_rtime, get_slot, load_slot, get_ctrlbutton, vm_tctrl, set_polar, set_rgb, set_hsb, and the clamp function. Gain insights into their syntax, parameters, and return values, with practical usage 
docTags: 
createdAt: 2021-12-08T18:02:03.000Z
---

Here we will cover a few functions available within your code, these functions&#x20;

| 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                                                                                                                                                                                                                          | ✔️  | ❌    |
| clamp function  | The clamp() function clamps a value between an upper and lower bound. clamp() enables selecting a middle value within a range of values between a defined minimum and maximum. It takes three parameters: a minimum value, a preferred value, and a maximum allowed value. | ✔️  | ❌    |

# get\_rtime

**get\_rtime&#x20;**&#x72;eturns 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:

:::BlockQuote
int days;
int hours;
int minutes;
int seconds;
int milliseconds;
main \{
&#x20;   milliseconds = milliseconds + get\_rtime();
&#x20;   if(milliseconds >= 1000) \{
&#x20;       milliseconds = milliseconds - 1000
&#x20;       seconds = seconds + 1;
&#x20;       if(seconds == 60) \{
&#x20;           seconds = 0;
&#x20;           minutes = minutes + 1;
&#x20;           if(minutes == 60) \{
&#x20;               minutes = 0;
&#x20;               hours = hours + 1;
&#x20;               if(hours == 24) \{
&#x20;                   hours = 0;
&#x20;                   days = days + 1;
&#x20;               }
&#x20;           }
&#x20;       }
&#x20;   }
&#x20;   set\_val(TRACE\_1, days);
&#x20;   set\_val(TRACE\_2, hours);
&#x20;   set\_val(TRACE\_3, minutes);
&#x20;   set\_val(TRACE\_4, seconds);
&#x20;   set\_val(TRACE\_5, milliseconds / 10);
}
:::

&#x20;🔴 **Syntax**

**&#xD;**&#x67;et\_rtime ( );

⚪&#x20;**Parameters**

**&#xD;**&#x4E;one

🔵&#x20;**Returns**

The elapsed time, in milliseconds, between the main iteration

[Main Section](https://app.archbee.io/public/spVpgjb6o1w4r69lkSod_/TKabiF5aDYcHTM18v2ya1)

# get\_slot

**get\_slot** returns an int value representing the current active slot of the Cronus Device.

:::BlockQuote
int \_currentSlot;
&#x20;
init \{
&#x20;    \_currentSlot = get\_slot();
&#x20;}
&#x20;
main \{
&#x20;
}
:::

&#x20;🔴 **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.

:::BlockQuote
main \{
&#x20;
&#x20;   if(event\_press(XB1\_RB))     // if RB / R2 is pressed...
&#x20;       load\_slot(5);           // Load slot 5
&#x20; &#x20;
&#x20;   if(event\_press(XB1\_LB))     // if LB / L2 is pressed...
&#x20;       load\_slot(0);           // Unload current slot and load slot 0
&#x20;
}
:::

&#x20;🔴 **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&#x20;**&#x72;eturns 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

:::BlockQuote
get\_ctrlbutton();
:::

&#x20;🔴 **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.

:::BlockQuote
main \{
&#x20;
&#x20;   vm\_tctrl(-5); // Run the VM every 5ms
&#x20;
}
:::

🔴&#x20;**Syntax**

**&#xD;**&#x76;m\_tctrl( \<variable> );

⚪&#x20;**Parameters**

**&#xD;**\<variable> : Numeric value to add to the Virtual Machine base time. Range -9 \~ 10

🔵&#x20;**Returns**

**&#xD;**&#x4E;othing

# set\_polar

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

:::BlockQuote
set\_polar(POLAR\_LS,250, 32000);
:::

&#x20;🔴 **Syntax¹ ² ³**

set\_polar(stick,angle,radius);

⚪ **Parameters**

stick: defined stick.

angle: index point of the bit to be set with a range of 0 to 359.

radius: index point of the bit to be set with a range of -32768 to 32767.

🔵 **Returns**

Nothing

# set\_rgb

Sets the LED on the ZEN to the supplied RGB color (Red,Green,Blue).

:::BlockQuote
set\_rgb(255,0,0) // red
set\_rgb(0,255,0)// green
set\_rgb(0,0,255) // blue
:::

&#x20;🔴 **Syntax¹ ² ³**

set\_rgb(red,green,blue);

⚪ **Parameters**

- red: index point of the bit to be set with a range of 0 - 255
- green: index point of the bit to be set with a range of 0 - 255
- blue: index point of the bit to be set with a range of 0 - 255

🔵 **Returns**

Nothing

# set\_hsb

set\_hsb sets the LED colors on the Zen eyes or a Playstation controller based on the Hue, Saturation, and Brightness.

:::BlockQuote
set\_hsb(300, 55, 70);
:::

🔴 **Syntax¹ ² ³**

set\_hsb( Hue, Saturation, Brightness);

⚪ **Parameters**

- hue: index point of the bit to be set with a range of 0 - 359
- saturation: index point of the bit to be set with a range of 0 - 100&#x20;
- brightness: index point of the bit to be set with a range of 0 - 100

🔵 **Returns**

Nothing

# clamp function

The clamp function clamps *x* to the range *\[min, max]*.

:::BlockQuote
int x = -10;

main \{

&#x20;   if (event\_press(PS4\_TRIANGLE))&#x20;
&#x20;       x = clamp(x++, -10, 10);
&#x20;  &#x20;
&#x20;   if (event\_press(PS4\_CROSS))&#x20;
&#x20;       x = clamp(x--, -10, 10);
&#x20;      &#x20;
&#x20;   set\_val(TRACE\_1,x);
}
:::

&#x20;🔴 **Syntax¹ ² ³**

clamp(x, min, max)

⚪ **Parameters**

x— The number to clamp.
min— Lower bound of range to which x is clamped. Minimum value returned.
max— Upper bound of range to which x is clamped. Maximum value returned.

🔵 Returns

Returns min if x is less than min, max if x is greater than max, and x otherwise.;
