Free-form input places an assignment, expression, or Arduino function call directly in a box function.
This ladder screen uses a free-form box function to call a function from Arduino code.
Choose Free in the command palette and enter one supported expression. It runs when the left condition is ON; with no contact, it runs every scan.
| Form | Input | Meaning |
|---|---|---|
| Assignment | D0 = (D1 + 10) * 2 | Store a result in a writable address |
| Function result | D0 = readSensor() | Store an Arduino function's return value |
| Standalone call | doWork() | Run a function without storing its return value |
D0 = D0 + 1 increments D0 each time it runs. Compound assignments such as R0 += 1.5 are also supported.
| Operator | Meaning |
|---|---|
= | Store the right-hand result in the target |
+= -= *= /= %= | Calculate with the target and store back in it |
&= |= ^= «= »= | Store a bit-operation or shift result back in the target |
You can call a function written in Arduino code. If it returns a value, store it in memory as in D0 = readSensor().
int readSensor() { // Read A0 with the standard Arduino function and return the value. return analogRead(A0); }
Enter D0 = readSensor() in the box function. When the left condition is ON, the function runs and stores its return value in D0.
Use REAL, DW, WD, UD, or UW to state the data format used in a calculation. Put the value to convert in parentheses.
| Command | Meaning |
|---|---|
REAL(D0) | Convert to 32-bit float; use to make integer division floating-point |
DW(D0) | Convert to signed 32-bit integer |
WD(DD0) | Convert to signed 16-bit integer; upper bits may be discarded |
UD(D0) | Convert to unsigned 32-bit integer |
UW(DD0) | Convert to unsigned 16-bit integer; upper bits may be discarded |
Enter cast names in uppercase and put exactly one value in parentheses. Use a cast in a right-hand expression, not on the left of an assignment.
| Symptom | What to check |
|---|---|
| The function cannot be found. | Check that it is declared in Arduino code with the same spelling and case. |
| A value increases too quickly. | With no contact it runs every scan. Use a positive-edge contact to run once. |