plcLib (Arduino): Single Bit Input / Output

The plcLib software allows single bit inputs inputs and outputs to be controlled in either normally off or normally on forms. A normally on input is equivalent to a push-to-make switch, and is represented by a pair of vertical lines in the ladder diagram. A push-to-break switch gives a normally closed connection and this is shown by adding a diagonal line between the vertical contacts. A similar arrangement is used for outputs which are shown either as a pair of curved lines (or even a complete circle), with a diagonal line added for an inverted output. The ladder diagram below shows the input and output of values in normal and inverted forms.

The ladder diagram may be easily converted to a text-based sketch, as shown below.

#include <plcLib.h>

/* Programmable Logic Controller Library for the Arduino and Compatibles

   Digital Input Output - Single bit I/O in normal and inverted forms

   Connections:
   Input - switch connected to input X0 (Arduino pin A0)
   Input - switch connected to input X1 (Arduino pin A1)
   Input - switch connected to input X2 (Arduino pin A2)
   Input - switch connected to input X3 (Arduino pin A3)
   Output - LED connected to output Y0 (Arduino pin 3)
   Output - LED connected to output Y1 (Arduino pin 5)
   Output - LED connected to output Y2 (Arduino pin 6)
   Output - LED connected to output Y3 (Arduino pin 9)

   Software and Documentation:
   http://www.electronics-micros.com/software-hardware/plclib-arduino/

*/
   
void setup() {
  setupPLC();  // Setup inputs and outputs
}

void loop() {
  in(X0);      // Read Input 0
  out(Y0);     // Send to Output 0

  inNot(X1);   // Read Input 1 (inverted)
  out(Y1);     // Send to Output 1

  in(X2);      // Read Input 2
  outNot(Y2);  // Send to Output 2 (inverted)
  
  inNot(X3);   // Read Input 3 (inverted) and send to Output 3 (inverted)
  outNot(Y3);  // (The double negative cancels out)
}
Source location: File > Examples > plcLib > inputOutput > DigitalInputOutput

The PLC software repeatedly calculates each rung of the ladder diagram in sequence – from left to right and top to bottom – by 'scanning' the inputs, performing calculations, and outputting the results; a process known as the scan cycle. Each rung of the ladder diagram is effectively a separate task, and the computer shares its processing power between these tasks in a repeating sequence. The high processing speed makes it appear that the PLC is performing several activities at the same time.

Inputs may be connected in series or parallel to create simple Boolean Logic (combinational logic) functions, as discussed in the next section.

Related Topics

top