Skip to main content

Variables

Overview​

Variables in HMCLS programs are 32-bit signed integers (int32_t). A program can have up to 32 variables, indexed 0–31.

Variables persist across loop iterations — their values are never reset when the loop restarts. Only declare variable (in Setup) sets the initial value.

Declaring Variables​

Every variable must be declared before use. Always place declare variable blocks in the Setup section.

Variables
declare variablenamecounterinitial0
important

All declare variable blocks must be in Setup, not Loop.

Variable Operations​

Variables
set to numbercounter=500
Variables
add (+)counter+=1
Variables
subtract (−)counter-=1
Variables
multiply (×)counter×=2
Variables
divide (//)counter//=2
Variables
modulo (%)counter%=10
Variables
set (expression)tmp = counter % 100 < 50
BlockOperationNotes
declare variableCreates a variable with an initial valueSetup only
set to numberAssigns a constant—
add (+)v = v + amountAmount can be variable or constant
subtract (−)v = v − amount—
multiply (×)v = v × amount—
divide (//)v = v ÷ amount (integer)Division by zero stops the script
modulo (%)v = v % amount—
set (expression)Inline expression stringParsed by compiler; advanced use
SETUP
Variables
declare variablenamecounterinitial0
LOOP ~1 kHz
Variables
add (+)counter+=1
Control
ifcounter>=1000
Variables
set to numbercounter=0
IO
LED toggleLED1 (green)

This toggles LED1 every 1000 loop iterations (≈ 1 second at 1 kHz).