plcLib (Arduino): Command Reference

This page lists all commands supported by the plcLib software.

General Configuration

Command Description Example Manual Page
setupPLC();
Configures basic PLC settings.
setupPLC();
Configuring the Hardware
Notes
  1. setupPLC() is an optional command which configures data directions for the default set of inputs and outputs, together with initial output values, as discussed in the Configuring the Hardware section. This command is typically omitted if a custom input/output allocation is being used, as discussed in the Defining Custom IO Allocations section.
  2. The #define noPinDefs option, which is available with Version 1.2 or later, prevents creation and configuration of standard inputs and outputs (X0, X1, X2, ..., Y0, Y1, Y2, ...). If used, this setting must appear before the inclusion of the PLC library.

Single Bit Digital Input / Output

Command Description Example Manual Page
in(input);
Reads a digital input.
in(X0);
Single Bit Input / Output
out(output);
Outputs to a digital output.
out(Y0);
Single Bit Input / Output
inNot(input);
Reads an inverted digital input.
inNot(X0);
Single Bit Input / Output
outNot(output);
Outputs an inverted signal to a digital output.
outNot(Y0);
Single Bit Input / Output

Combinational Logic

Command Description Example Manual Page
andBit(input);
Logical AND with a digital input.
in(X0);
andBit(X1);
out(Y0);
Performing Boolean Operations
orBit(input);
Logical OR with a digital input.
in(X0);
orBit(X1);
out(Y0);
Performing Boolean Operations
xorBit(input);
Logical XOR with a digital input.
in(X0);
xorBit(X1);
out(Y0);
Performing Boolean Operations
andNotBit(input);
Logical AND with an inverted digital input.
in(X0);
andNotBit(X1);
out(Y0);
Performing Boolean Operations
orNotBit(input);
Logical OR with an inverted digital input.
in(X0);
orNotBit(X1);
out(Y0);
Performing Boolean Operations
Notes
  1. To create a NAND or NOR function, start with the appropriate AND / OR example above, replacing the out() command with outNot().
  2. AND- and OR-based examples may be extended to have more than two inputs, if required.
  3. Methods of solving complex (multiple branch) logic circuits are discussed in the Using Variables in Programs and Stack-based Storage and Logic sections.

Analogue Signal Input / Output

Command Description Example Manual Page
inAnalog(input);
Reads an analogue input.
inAnalog(X0);
Working with Analogue Signals
outPWM(output);
Outputs a PWM waveform.
outPWM(Y0);
Working with Analogue Signals
outServo(output);
Outputs to a servo.
outServo(Y0);
Working with Analogue Signals
Notes
  1. Analogue input values are in the range 0–1023 (based on a standard 10-bit A–D converter). Output values are automatically scaled to match the output type (0–255 for PWM or 0–180° for a servo.)
  2. The outServo() command requires the Arduino Servo library. The associated function must be locally defined, as explained in the Working with Analogue Signals section.

Comparing Analogue Signals

Command Description Example Manual Page
compareGT(input);
Compare an analogue input with a second analogue value, returning 1 if the former is larger.
inAnalog(X0);
compareGT(X1);
out(Y0);
Comparing Analogue Values
compareLT(input);
Compare an analogue input with a second analogue value, returning 1 if the former is smaller.
inAnalog(X0);
compareLT(X1);
out(Y0);
Comparing Analogue Values
Notes
  1. To compare an analogue input with a fixed threshold, replace the input parameter of the compare command with a user specified variable of type 'unsigned int', and assigned a value in the range
    0–1023.

Latches

Command Description Example Manual Page
latch(latch_output, reset_input);
Latches the previous digital input value.
in(X0);
latch(Y0, X1);
Latching Outputs
latchKey(set_key, reset_key, output);
Latches a digital output based on keypad entry.
latchKey('1', '2', Y0);
Inputting from a Keypad
set(latch_output);
Latches (sets) a digital output if the previous value is true.
in(X0);
set(Y0);
Latching Outputs
reset(latch_output);
Clears (unsets) a latched output if the previous value is true.
in(X0);
reset(Y0);
Latching Outputs
Notes
  1. The latchKey() command requires the Keypad library. The associated function must be locally defined, as explained in the Inputting from a Keypad section.

Timers

Command Description Example Manual Page
timerOn(timer_variable, delay_ms);
Produces a delayed output after an input is enabled.
in(X0);
timerOn(TIMER0, 2000);
out(Y0);
Using Time Delays
timerOff(timer_variable, delay_ms);
Delays turning an output off after an input is removed.
in(X0);
timerOff(TIMER0, 2000);
out(Y0);
Using Time Delays
timerPulse(timer_variable, pulse_ms);
Produces a fixed width pulse triggered by a brief3 input.
in(X0);
timerPulse(TIMER0, 2000);
out(Y0);
Using Time Delays
timerCycle(low_variable, low_ms, 
   high_variable, high_ms);
Creates a repeating pulse waveform, if enabled.
in(X0);
timerCycle(AUX0, 900, AUX1, 100);
out(Y0);
Producing Repeating Waveforms
Notes
  1. Elapsed timer variables should be defined of type unsigned long (e.g. unsigned long TIMER0 = 0;).
  2. The timerPulse() command is available with Version 1.0 or later of the plcLib software.
  3. The timerPulse() command is modified in Version 1.1 to be edge triggered, rather than level triggered. This prevents the timer from being automatically re-triggered if the trigger input is still high when the fixed width pulse finishes.

Edge Triggered Pulses

Command Description Example Manual Page
Pulse pulse_name;
Creates a pulse object.
Pulse pulse1;
Edge Triggered Pulses
pulse_name.inClock();
Connects an input signal to the pulse object.
in(X0);
pulse1.inClock();
Edge Triggered Pulses
pulse_name.rising();
Read rising edge of pulse waveform1.
pulse1.rising();
out(Y0);
Edge Triggered Pulses
pulse_name.falling();
Read falling edge of pulse waveform1.
pulse1.falling();
out(Y1);
Edge Triggered Pulses
Notes
  1. Pulses generated by rising or falling edges are active for a single scan cycle only.

Counters

Command Description Example Manual Page
Counter counter_name(preset_value
   [, direction]);
Creates and configures a counter object1.
Counter ctr1(5);
Counter ctr2(10,1);
Counting and Counters
counter_name.countUp();
Counts up, if count is less than preset value2, 3.
in(X0);
ctr1.countUp();
Counting and Counters
counter_name.countDown();
Counts down, if count is greater than zero2, 3.
in(X0);
ctr1.countDown();
Counting and Counters
counter_name.preset();
Sets the internal count to the preset value, activating the upperQ output3.
in(X1);
ctr1.preset();
Counting and Counters
counter_name.clear();
Sets the internal count to zero, activating the lowerQ output3.
in(X2);
ctr1.clear();
Counting and Counters
counter_name.upperQ();
Equal to 1 if the internal count is equal to the preset value, 0 otherwise.
ctr1.upperQ();
out(Y0);
Counting and Counters
counter_name.lowerQ();
Equal to 1 if the internal count is equal to zero, 0 otherwise.
ctr1.lowerQ();
out(Y0);
Counting and Counters
counter_name.count();
Returns the internal count value.
Serial.println(ctr1.count());
Counting and Counters
counter_name.presetValue();
Returns the preset value.
Serial.println(ctr1.presetValue());
Counting and Counters
Notes
  1. A newly created counter object is configured with a preset value (upper count limit) specified by the first parameter. If a single parameter is supplied, or the optional second parameter is 0, then the initial count value is set to 0, which is suitable for an up counter. A non-zero second parameter value causes the internal count value to be set to the preset value, which is effectively the start position for a down counter.
  2. A debounced switch input, provided by an on-delay timer, may be used to prevent multiple triggering when connecting a switch to a counter input.
  3. The countUp, countDown, preset, and clear counter methods are conditionally enabled by the result of the previous instruction, which will often be produced by reading a switch.
  4. Counter commands are available with Version 0.8 or later of the plcLib software.

Shift Registers

Command Description Example Manual Page
Shift register_name([start_value]);
Creates and configures a shift register object1.
Shift shift1();
Shift shift2(0x8888);
Shifting and Rotating Binary Data
register_name.inputBit();
Sets the serial input bit based on the previous input.
in(X0);
shift1.inputBit();
Shifting and Rotating Binary Data
register_name.shiftLeft();
Shifts data one place to the left, on the rising edge of the previous input.
in(X1);
shift1.shiftLeft();
Shifting and Rotating Binary Data
register_name.shiftRight();
Shifts data one place to the right, on the rising edge of the previous input.
in(X2);
shift1.shiftRight();
Shifting and Rotating Binary Data
register_name.reset();
Resets the internal shift register value to zero if the previous input is equal to 1.
in(X3);
shift1.reset();
Shifting and Rotating Binary Data
register_name.bitValue(bit_position);
Returns the value of the shift register bit at the specified position.
shift1.bitValue(0);
out(Y0);
Shifting and Rotating Binary Data
register_name.value();
Returns the value of the shift register as an unsigned integer2.
Serial.println(shift1.value());
delay(200);
Shifting and Rotating Binary Data
Notes
  1. Shift registers have a fixed data width of 16 bits. A newly created shift register object has a default value of 0x0000 if no parameter is specified, or a start value specified by the first parameter in the range 0X0000–0XFFFF.
  2. The ability to read the shift register value is useful when debugging shift register applications.
  3. Shift register commands are available with Version 0.9 or later of the plcLib software.

Stack and Block Logic

Command Description Example Manual Page
Stack stack_name;
Creates a single-bit, 32-level stack.
Stack stack1;
Stack-based Storage and Logic
stack_name.push();
Pushes the scanValue, expressed as a single-bit number, onto the stack.
stack1.push();
Stack-based Storage and Logic
stack_name.pop();
Updates the scanValue with a single-bit value removed from the stack.
stack1.pop();
Stack-based Storage and Logic
stack_name.andBlock();
ANDs the current scanValue with a single-bit value removed from the stack.
stack1.andBlock();
Stack-based Storage and Logic
stack_name.orBlock();
ORs the current scanValue with a single-bit value removed from the stack.
stack1.orBlock();
Stack-based Storage and Logic
Notes
  1. Stack-based commands are available with Version 1.0 or later of the plcLib software.

Related Topics

top