#define camshaft1 13
#define camshaft2 12
#define relay1 9
#define relay2 8
#define relay3 7
#define relay4 6
int x = 0; // Remove redundant declaration
static int g1 = 0;
static int g2 = 0;
static int x2 = 0;
void setup() {
Serial.begin(115200);
pinMode(camshaft1, INPUT_PULLUP);
pinMode(camshaft2, INPUT_PULLUP);
pinMode(relay1, OUTPUT); // Changed to OUTPUT
pinMode(relay2, OUTPUT); // Changed to OUTPUT
pinMode(relay3, OUTPUT); // Changed to OUTPUT
}
void loop() {
static int x = 0; // Initialize x if needed
static int g1 = 0;
static int g2 = 0;
if (digitalRead(camshaft1) == LOW) {
g1++;
} else if (digitalRead(camshaft2) == LOW) {
g2++;
}
int x2 = g1 + g2 ;
if (x2 > 4) {
g2 = 0;
g1 = 0;
x2 = 0;}
Serial.print("x2 :- ");
Serial.println(x2);
Serial.print("g2 :- ");
Serial.println(g2);
Serial.print("g1 :- ");
Serial.println(g1);
delay(50);
}