Sorry, I did not find a HW or SW category for that older board use.
All my goals, headaches and success in this Ino code for my model RR. Is there a Forum category for Model RR?
/* D:\01-IT-HW\19-PLC-PC-Arduino\23-Arduino SW Proj\01-SamplesSketches\23-ModelRRCTrl\23-MgleisWeichCtrl-01
Weichenschaltung RR turnout 2 tracks Version 2_1
Function description:
Uno R3 CPU use for RR main line bypass use with two turnouts, 4 5V relais to operate their coils and four operator console status LED.
The RR main line and bypass line have 2 IR sensors on the Analog Ardu Uno inputs.
Open development items:
2) 9/9/24 PB LED working, console LED not in ino line 168. No idea why?
3) Two IR detectors for main line 1 and two for bypass line 2 not integrated. Since the trains have different lenghts, I want to use an bool OR function.
Please advice with an example to correctly declare and process them. Keep in mind that the train may stop at each in between cars and miss one.
I will position the first that it definetly sees the engine.
4) External 24L256 EEprom shall store the console LED status to have them present at the next time you turn the Ardu Uno power on.
Please advice if I shall use bool true / false status byte storage in an example. Sorry as a novice, I looked at many external EEprom examples. I could not
find a specific one for my case.
Many thanks
Last modified Henry: 9/9/24
Weichenspulen sollten nur eine bestimmte kurze Zeit geschaltet werden. turnout relays are ON for 1/2 second
if (millis() - RELAIS1G_timestore > 1000 ) //Schaltzeit Relais 1 Sek.
*/
// Umbenenen der STM Pins // Lichtschranke zur Gleisbesetzmeldung LSBG1-5
const int LSBG1 = A0; // Lichtschranke Gleisbesetzt Gleis 1 train detector front main track line 1
const int LSBG2 = A1; // Lichtschranke Gleisbesetzt Gleis 1 train detector rear end main track line 1
const int LSBG3 = A2; // Lichtschranke Gleisbesetzt Gleis 2 train detector front bypass track line 2
const int LSBG4 = A3; // Lichtschranke Gleisbesetzt Gleis 2 train detector rear end bypass track line 2
const int W1APB1 = 2; // Weiche 1 abbiegen PB1 turnout turn
const int W1GPB2 = 3; // Weiche 1 geradeaus PB2 turnout straight
const int W2APB1 = 4; // Weiche 2 abbiegen PB1 turnout turn
const int W2GPB2 = 5; // Weiche 2 geradeaus PB2 turnout straight
int W1APB1State = 0; int W1GPB2State = 0;
int W2APB1State = 0; int W2GPB2State = 0;
const int W1A = 7; // Weiche 1 Abbiegen turnout 1 turn relay pin 7
const int W1G = 8; // Weiche 1 Geradeaus turnout 1 straight relay pin 8
const int W2A = 9; // Weiche 2 Abbiegen turnout 2 turn relay pin 9
const int W2G = 10; // Weiche 2 Geradeaus turnout 2 straight relay pin 10
const int W1Aled = 11; // Weiche 1 Abbiegen turnout 1 turn pin 11
const int W1Gled = 12; // Weiche 1 Geradeaus turnout 1 straight pin 12
const int W2Aled = 13; // Weiche 2 Abbiegen turnout 2 turn pin 13
const int W2Gled = A6; // Weiche 2 Geradeaus turnout 2 straight pin A6
int W1AState = 0; // Weiche 1 Abbiegen turnout 1 turn
int W1GState = 0; // Weiche 1 Geradeaus turnout 1 straight
int W2AState = 0; // Weiche 2 Abbiegen turnout 2 turn
int W2GState = 0; // Weiche 2 Geradeaus turnout 2 straight
int W1AledState = 0;
int W1GledState = 0;
int W2AledState = 0;
int W2GledState = 0;
// variable definieren
// Variablen Relais Ausgaenge fuer Weichen
bool geschaltetW1A = false; // Variable fuer Weiche1 pin 10 Abbiegen A turnout 1 turn
bool geschaltetW1G = false; // Variable fuer Weiche1 pin 11 Geradeaus G turnout 1 straight
bool geschaltetW2A = false; // Variable fuer Weiche2 pin 12 Abbiegen turnout 2 turn
bool geschaltetW2G = false; // Variable fuer Weiche2 pin 13 Geradeaus turnout 2 straight
int empfindlichkeit = 200;
unsigned long RELAIS1G_timestore; // Variable Speicher fuer Systemzeit.Weiche1 Geradeaus G turnout 1 straight
unsigned long RELAIS1A_timestore;
unsigned long RELAIS2G_timestore; // Variable Speicher fuer Systemzeit.Weiche2 Geradeaus turnout 2 straight
unsigned long RELAIS2A_timestore;
void setup() { // put your setup code here, to run once:
Serial.begin(9600);
// Pin mode
pinMode(W1APB1, INPUT_PULLUP); // Weiche 1 abbiegen PB1
pinMode(W1GPB2, INPUT_PULLUP); // Weiche 1 geradeaus PB2 turnout 1 straight
pinMode(W2APB1, INPUT_PULLUP); // Weiche 2 abbiegen PB1 turnout 2 turn
pinMode(W2GPB2, INPUT_PULLUP); // Weiche 2 geradeaus PB2
pinMode(W1A, OUTPUT); // Weiche 1 Abbiegen RRSW turn 1 pin 10
pinMode(W1G, OUTPUT); // Weiche 1 Geradeaus RRSW straight pin 11
pinMode(W2A, OUTPUT); // Weiche 2 Abbiegen RRSW turn pin 12
pinMode(W2G, OUTPUT); // Weiche 2 Geradeaus RRSW straight pin 13
pinMode(W1Aled, OUTPUT); // Weiche 1 Abbiegen RRSW console LED turn pin 11
pinMode(W1Gled, OUTPUT); // Weiche 1 Geradeaus RRSW console LED straight pin 12
pinMode(W2Aled, OUTPUT); // Weiche 2 Abbiegen RRSW console LED turn pin 13
pinMode(W2Gled, OUTPUT); // Weiche 2 Geradeaus RRSW console LED straight pin
}
void loop()
{
W1APB1State = digitalRead(W1APB1);
W1GPB2State = digitalRead(W1GPB2);
W2APB1State = digitalRead(W2APB1);
W2GPB2State = digitalRead(W2GPB2);
// weiche 1 abbiegen turn PB relay
if (W1APB1State == LOW)
{
digitalWrite (W1A, HIGH); // Weiche 1 Abbiegen turnout 1 turn
(W1AledState = HIGH);
Serial.println("W1 turn");
RELAIS1A_timestore = millis();
}
if (millis() - RELAIS1A_timestore > 500 ) //Schaltzeit Relais time
{
digitalWrite(W1A, LOW); // Weiche 1 Abbiegen turnout 1 turn
W1APB1State = LOW;
}
if (W1GPB2State == LOW) //Weiche 1 geradeaus turnout 1 straight
{
digitalWrite (W1G, HIGH); // Weiche 1 geradeaus
(W1GledState = HIGH);
Serial.println("W1 straight");
RELAIS1G_timestore = millis();
}
if (millis() - RELAIS1G_timestore > 500 ) //Schaltzeit Relais
{
digitalWrite(W1G, LOW); // Weiche 1 geradeaus
W1GPB2State = LOW;}
// Weiche 2 turn abbiegen PB Relay
if (W2APB1State == LOW)
{
digitalWrite (W2A, HIGH); // Weiche 2 Abbiegen
W2APB1State = HIGH;
Serial.println("W2 turn");
RELAIS2A_timestore = millis();
}
if (millis() - RELAIS2A_timestore > 500 ) //Schaltzeit Relais
{
digitalWrite(W2A, LOW); // Weiche 2 Abbiegen
W2APB1State = LOW;
}
if (W2GPB2State == LOW)
{
// Weiche 2 geradeaus straight PB
digitalWrite (W2G, HIGH); // Weiche 2 geradeaus
W2GPB2State = HIGH;
Serial.println("W2 straight");
RELAIS2G_timestore = millis();
}
if (millis() - RELAIS2G_timestore > 500 ) //Schaltzeit Relais
{
digitalWrite(W2G, LOW); // Weiche 2 geradeaus
W2GPB2State = LOW;
}
}
void ConsoleLED () {
// Weiche W1A console abbiegen turn LED
if (W1AledState == HIGH && W1GledState == LOW);
{
digitalWrite (W1Aled, HIGH);
Serial.println("W1A LED turn ON");
}
if (W1AledState == LOW && W1GledState == HIGH);
{
digitalWrite (W1Aled, LOW);
}
// Weiche W1G console geradeaus straight LED
if (W1AledState == LOW && W1GledState == HIGH);
{
digitalWrite (W1Gled, HIGH);
Serial.println("W1G LED straight ON");
}
if (W1AledState == HIGH && W1GledState == LOW);
{
digitalWrite (W1Gled, LOW);
}
// Weiche W2A console abbiegen turn LED
if (W2AledState == HIGH && W2GledState == LOW);
{
digitalWrite (W2Aled, HIGH);
Serial.println("W2A LED turn ON");
}
if (W2AledState == LOW && W2GledState == HIGH);
{
digitalWrite (W2Aled, LOW);
}
// Weiche W2G console geradeaus straight LED
if (W2AledState == LOW && W2GledState == HIGH);
{
digitalWrite (W2Gled, HIGH);
}
if (W2AledState == HIGH && W2GledState == LOW);
{
digitalWrite (W2Gled, LOW);
}
}
/*
//Weiche 1 geradeaus straight PB relay}
* Serial.println("W1 turn");
* Serial.println("W1 straight");
* Serial.println("W2 turn");
* Serial.println("W2 straight");
*/