I have been working on this for quite a while and eventually thought I had cracked the problem with the operation and having added 2 out of 6 Detection Blocks I thought I had cracked it but ... Murphy gets you every time ...
Got Detection Block working fine on its own ... aded the extra code for Detection block 2 and works fine ... BUT ... I fine that as Detection Block 1 the pointswp1 goes LOW when not in use so when Detection Block 2 operation pointswp1 LED comes on and goes off (using LEDs to test) and this is because it see's pointswp1 in Detection 1 is LOW so that is the problem ...
SO my best option is to change the Void Loops into State machine i.e Switch Case but I am unsure how to start to modify the sketch using the enum and switch statements ... I am a novice programmer so would be grateful for help ..
John
void loop() {
BlockState1 = digitalRead(BlockDet1);
BlockState2 = digitalRead(BlockDet2);
BlockState3 = digitalRead(BlockDet3);
BlockState4 = digitalRead(BlockDet4);
BlockState5 = digitalRead(BlockDet5);
BlockState6 = digitalRead(BlockDet6);
BlockState7 = digitalRead(BlockDet7);
BlockState8 = digitalRead(BlockDet8);
BlockState9 = digitalRead(BlockDet9);
BlockState10 = digitalRead(BlockDet10);
Buttonval1 = digitalRead(P1button); // Read the Button 1 Value
Buttonval2 = digitalRead(P2button); // Read the Button 2 Value
Buttonval3 = digitalRead(P3button); // Read the Button 3 Value
//#################################### Detection 1 Sensor 6 #############################
// Checking Block State operation
// Track 1 South leading to Darcy Loop via Point P1
// Sensors Used - Sensor 6
Serial.print(" ");
Serial.print("Button Value ");
Serial.println(Buttonval1);
Serial.print("Block State 6 ");
Serial.print(BlockState6);
if (BlockState6 == HIGH && Buttonval1 == HIGH ) { //Start of Sensor 6 detection Output of Timer Block goes HIGH when detection of Sensor 6
digitalWrite (senseLed1, HIGH);// Turns Mimic panel Sense 1 LED ON
}
if (BlockState6 == HIGH && Buttonval1 == LOW ) { //Start of Sensor 6 detection Output of Timer Block goes HIGH when detection of Sensor
//All point operation is via a HIGH/LOW input via an input resistor on a 2N7000 switching a Servo via a MERG SERVO4 controller
//Also to a Nano control for Mimic Panel LED's
digitalWrite(pointswp1, HIGH); // Operate Points P1, Left to Darcy Loop
delay(200); //Delay for Red to Green Signal
digitalWrite(signalPinsBicol1,LOW);// Turn GREEN Signal ON
}
if (BlockState6 == LOW) { //From Sensor 6 Entry detection Sensor 10 Holds Timer Output HIGH till Last Carraige has Exit Block
digitalWrite(signalPinsBicol1,HIGH);// Turn Red Signal ON
// digitalWrite(pointswp1, LOW); // Operate Points P1, Back to Straight ahead position
digitalWrite (senseLed1, LOW); // Turn Mimic panel Sense LED off
}
//#################################### Detection 2 Sensor 3 #############################
// Checking Block State operation
// Darcy Loop leading to Track 4
// Sensors Used
if (BlockState3 == HIGH && Buttonval2 == HIGH) { // Start of IR Sensor 3 detection Output of Timer Block goes HIGH when detection of IR Sensor
digitalWrite(senseLed2, HIGH);// Turns Mimic panel Sense 2 LED ON
}
if (BlockState3 == HIGH && Buttonval2 == LOW ) { //Start of Sensor 6 detection Output of Timer Block goes HIGH when detection of Sensor {
//All point operation is via a HIGH/LOW input via an input resistor on a 2N7000 switching a Servo via a MERG SERVO4 controller
//Also to a Nano control for Mimic Panel LED's
digitalWrite(pointswp1, HIGH); // Operate Points P1 To Left from Darcy Loop
digitalWrite(pointswp2, HIGH); // Operate Points P2 To Left from Darcy Loop
digitalWrite(pointswp6, HIGH); // Operate Points P6 To Left from Track 2 to 4
digitalWrite(pointswp7, HIGH); // Operate Points P7 To Left Double Slip
digitalWrite(pointswp8, HIGH); // Operate Points P8 To Left Double Slip
digitalWrite(pointswp9, HIGH); // Operate Points P9 To Left to line 4 from Double Slip
delay(500); //Delay for Signal Red to Green
digitalWrite(signalPinsBicol2,LOW);// Turn GREEN Signal ON
}
if (BlockState3 == LOW) { // From Sensor 3 Entry detection Sensor 5 Holds Timer Output HIGH till Last Carraige has Exit Block
digitalWrite(signalPinsBicol2,HIGH);// Turn Red Signal ON
digitalWrite(pointswp1, LOW); // Operate Points P1 back to Straight
digitalWrite(pointswp2, LOW); // Operate Points P2 back to Straight
digitalWrite(pointswp6, LOW); // Operate Points P6 back to Straight
digitalWrite(pointswp7, LOW); // Operate Points P7 back to Straight
digitalWrite(pointswp8, LOW); // Operate Points P8 back to Straight
digitalWrite(pointswp9, LOW); // Operate Points P9 back to Straight
digitalWrite(senseLed2, LOW); // Turn Mimic panel Sense LED off
}
}