Hello anyone !
I have made a program using two libraries plcLib.h and elapsedMillis.h . I am wsing elapsedMillis to measure the time thet an input is turned ON and this time is recorded as an variable . This variabel is used to change two timers TON and TOFF . This is not using corect and i dont understand why ??? Anyone help me please ???
#include <plcLib.h>
#include <elapsedMillis.h>
const int switchPin = A3;
unsigned long TIMER0 = 0; // Variable to hold elapsed time for Timer 0
unsigned long TIMER1 = 0; // Variable to hold elapsed time for Timer 0
unsigned long TIMER3 = 0;
unsigned int AUX0; // Latch output variable
unsigned int AUX1; // Latch reset variable
unsigned int AUX2;
unsigned int AUX3;
unsigned int AUX4;
long val;
void setup() {
Serial.begin(9600);
setupPLC(); // Setup inputs and outputs
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH); // turn on pull-up resistor
Serial.begin(9600);
Serial.println("Press and release switch" );
}
void loop() {
val = pulseIn(switchPin, LOW , 5000);
if( val != 0) // timeout returns 0
{
Serial.print("switch pressed for ");
Serial.print(val);
Serial.println(" microseconds");
}
AUX1 = in(X2); // AUX1 (Reset) controlled by input X1
in(X0);
latch(AUX3,X1);
in(AUX1); // Read switch connected to Input 0 (Set input - Input 0)
latch(AUX0,AUX2); // Latch command, Output = AUX0, Reset = AUX1 (Input 1)
in(AUX0);
timerOn(TIMER0,val*2);
out(AUX2);
in(AUX2);
timerOff(TIMER1, 800);
outNot(AUX4);
in(AUX3);
andBit(AUX4);
out(Y0);
}
Moderator edit: illegible yellow removed
Moderator edit: Code posted to save hassle of downloading.
kontrolli_me_timera.ino (1.22 KB)