A5.h - Proton-Electronics/proton-plc GitHub Wiki

Reference Class Proton_Arduino_PLC

Proton_Arduino_PLC add more function programming language can be divided in three main parts: functions, values (variables and constants), and structure.

Functions

read

Reads the value from a specified digital input, either HIGH or LOW or Analog value.

Syntax

.read(pin);

Parameters

pin: D1, D2, D3, D4, D5, D6, A1, A2, A3, A4, REL1, REL2, REL3, REL4, REL5.

Returns

HIGH or LOW or Value 0 to 1024.

Example

Proton_Arduino_PLC plc;
void loop() {
  int val;
  val = plc.read(D1);           // read the digital input pin 1
  Serial.println(val);          // debug value
  val = plc.read(A1);           // read the analog input pin 1
  Serial.println(val);          // debug value
}

write

Writes an analog value to a pin AO1 or AO2.

Syntax

.write(pin, value);

Parameters

pin: AO1, AO2.

Returns

Nothing.

Example

Proton_Arduino_PLC plc;
void loop() {
  val = plc.a1();   // read the input pin A1
  plc.write(AO1, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

d1..d6

Reads the value from a specified digital input, either HIGH or LOW.

Syntax

.d1();
.d2();
.d3();
.d4();
.d5();
.d6();

Parameters

Nothing.

Returns

HIGH or LOW.

Example

Proton_Arduino_PLC plc;
void loop() {
  int val = plc.d1();   // read the input D1
  plc.rel1(val);        // sets the relay 1 to the digital input 1
}

a1..a4

Reads the value from the specified analog pin. A1 .. A4.

Syntax

.a1();
.a2();
.a3();
.a4();

Parameters

Nothing.

Returns

The analog reading on the pin. Although it is limited to the resolution of the analog to digital converter (0-1023 for 10 bits). Data type: int.

Example

Proton_Arduino_PLC plc;

void setup() {
  Serial.begin(9600);           //  setup serial
}

void loop() {
  val = plc.a1();               // read the input pin
  Serial.println(val);          // debug value
}

ao1..ao2

Writes an analog value to a pin AO1 or AO2.

Syntax

.ao1(value);
.ao2(value);

Parameters

value: the duty cycle: between 0 (0v) and 255 (10v). Allowed data types: int.

Returns

Nothing.

Example

Proton_Arduino_PLC plc;
void loop() {
  val = plc.a1();   // read the input pin A1
  plc.ao1(val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

rel1..rel5

Write a HIGH or a LOW value to a relay.

Syntax

.rel1(value);
.rel2(value);
.rel3(value);
.rel4(value);
.rel5(value);

Parameters

value: HIGH or LOW or _ON or _OFF.

Returns

Nothing

Example

Proton_Arduino_PLC plc;
void loop() {
  plc.rel1(_ON);  // sets the relay 1 on
  delay(1000);    // waits for a second
  plc.rel1(_OFF); // sets the relay 1 off
  delay(1000);    // waits for a second
}

on

Set relay 1..5 to ON.

Syntax

.on(relay_pin);

Parameters

relay_pin: REL1, REL2, REL3, REL4, REL5.

Returns

Nothing.

Example

Proton_Arduino_PLC plc;
void loop() {
  plc.on(REL1); //
}

off

Set relay 1..5 to OFF.

Syntax

.off(relay_pin);

Parameters

relay_pin: REL1, REL2, REL3, REL4, REL5.

Returns

Nothing.

Example

Proton_Arduino_PLC plc;
void loop() {
  plc.off(REL1); //
}