plcLib - live

Simple PLC-style programming for the Arduino and compatibles.

Simulator Code

Local file to load: Local filename to save:

// Sample program // (Press F5 to reload sample program) TMR0 = new Timer(); CTR0 = new Counter(3); // Final count = 3, starting at zero function setup() { // Uncomment the following line, and also line 36 to enable data logging for timing diagrams // logVars("X0", "X1", "X2", "X3", "Y0", "Y1", "Y2"); // Optionally log variables for timing diagram (1 of 2) } function loop() { din(X0); // Read input X0 andBit(X1); // Logical AND with input X1 dout(Y0); // Send (X0 AND X1) to output Y0 din(X2); // Read input X2 timerOn(TMR0,1000); // 1 second on-delay dout(Y1); // Send delayed output to Y1 din(Y1); // Read output Y1 (delayed input X2) CTR0.countUp(); // Count up on each rising edge CTR0.upperQ(); // Display count finished on output Y2 dout(Y2); din(X3); // Read input X3 CTR0.clear(); // Clear counter (counter at lower limit) ain(AD0); // Read analogue input AD0 (= A0) pout(Y3); // PWM output to output Y3 // Uncomment the following line, and also line 10 to enable data logging for timing diagrams // logVars(X0, X1, X2, X3, Y0, Y1, Y2); // Optionally log variables for timing diagram (2 of 2) // console.log(CTR0.value()); // Optionally display current count //$delay(200); // 0.2 second loop delay in C++ for debugging purposes }

Simulation

InputsHardwareOutputs
Microcontroller
Y0
Y1
Y2
Y3

AD0

AD1

Select Target System:

Code will appear here...

Version 2.0, Beta 6, updated 12th November, 2023.

Copyright ©2023, the plcLib authors and contributors