{"id":746,"date":"2021-03-26T23:04:49","date_gmt":"2021-03-26T23:04:49","guid":{"rendered":"https:\/\/starthardware.org\/en\/?p=746"},"modified":"2021-03-28T08:58:47","modified_gmt":"2021-03-28T08:58:47","slug":"raylfx-train-station","status":"publish","type":"post","link":"https:\/\/starthardware.org\/en\/raylfx-train-station\/","title":{"rendered":"RaylFX \u2013 Train Station"},"content":{"rendered":"\n<p>This module of the <a href=\"https:\/\/starthardware.org\/en\/raylfx-effects-for-model-railroads-and-model-making-with-arduino-nano\/\" target=\"_blank\" rel=\"noreferrer noopener\">RaylFX system<\/a> controls an Arduino train station for the model railway. The functions include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>OLED-Departure display with changing content<\/li><li>Sound-module with verbal announcements<\/li><li>Train station lighting with fluorescent tube switch on effect<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Wiring Diagram<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-railway-train-station-oled-wiring-diagram-1024x495-1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"495\" src=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-railway-train-station-oled-wiring-diagram-1024x495-1.jpg\" alt=\"Arduino Train Station RaylFX OLED Wiring Diagram\" class=\"wp-image-748\" srcset=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-railway-train-station-oled-wiring-diagram-1024x495-1.jpg 1024w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-railway-train-station-oled-wiring-diagram-1024x495-1-300x145.jpg 300w, https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-railway-train-station-oled-wiring-diagram-1024x495-1-768x371.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>D2, D3: DFPlayer MP3 module<\/li><li>D4 \u2013 D12: LEDs as fluorescent tubes<\/li><li>A3: connection of the time signal from the conrol module<\/li><li>A4, A5: I2C connection to the OLED-display<\/li><\/ul>\n\n\n\n<p>Attention: At pin A3 (normally A4, but in this case A3) the control signal of the <a href=\"https:\/\/starthardware.org\/en\/raylfx-effects-for-model-railroads-and-model-making-with-arduino-nano\/\" target=\"_blank\" rel=\"noreferrer noopener\">RaylFX control module<\/a> is applied. It controls the time of day and is mandatory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Components<\/h2>\n\n\n\n<ul class=\"wp-block-list\" id=\"block-aa2bb72e-36ad-4f02-bf4d-f009a13b9d29\"><li>1x&nbsp;<a href=\"https:\/\/amzn.to\/2MCr0Yc\" target=\"_blank\" rel=\"noreferrer noopener\">Arduino Nano<\/a>*<\/li><li>1x&nbsp;<a href=\"https:\/\/amzn.to\/36nY4KH\" target=\"_blank\" rel=\"noreferrer noopener\">Breadboard and jumper wires<\/a>*<\/li><li>1x&nbsp;<a href=\"https:\/\/amzn.to\/2PJdwvx\" target=\"_blank\" rel=\"noreferrer noopener\">LED-Set<\/a>*<\/li><li><a href=\"https:\/\/amzn.to\/3c2DD9m\" target=\"_blank\" rel=\"noreferrer noopener\">1x OLED-display<\/a>*<\/li><li>1x <a href=\"https:\/\/amzn.to\/38XL7bM\" target=\"_blank\" rel=\"noreferrer noopener\">Electrolytic capacitor<\/a>* (100 \u2013 470\u00b5F) <\/li><li><a href=\"https:\/\/amzn.to\/3ofDLVO\" target=\"_blank\" rel=\"noreferrer noopener\">DFPlayer-Mini<\/a>* MP3 player module<\/li><li><a href=\"https:\/\/amzn.to\/3a1OyxQ\" target=\"_blank\" rel=\"noreferrer noopener\">Speaker<\/a>*<\/li><li>1x 1kOhm resistor<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Code Settings<\/h2>\n\n\n\n<p>This module also offers a number of adjustment options. The lighting of the train station can flicker like fluorescent tubes when switched on. The time that all lamps take to switch on can be set with the variable <em>flickerTimeLights<\/em>. The higher the value, the longer the lights flicker. The intensity of flickering can be set with the variable <em>flickerSpeed<\/em>.<\/p>\n\n\n\n<p>The announcements on the OLED display change randomly. The minimum duration per announcements can be set with the variable <em>announcementChangeMin<\/em>. A time between 0 and the value set in the variable <em>announcementChangeVariableTime<\/em> is added to it randomly.<\/p>\n\n\n\n<p>The texts on the display are defined in the <em>textSegments <\/em>array. It can be extended by further texts. For this purpose, the dimensions in the array and the variable <em>announcementCount <\/em>must be adjusted.<\/p>\n\n\n\n<p>The display automatically shows the current model railway time when switching. The follow-up trains are displayed at 30-minute intervals. So if the current time is 17:21, the departure times of the following trains are displayed 17:51 and 18:21.<\/p>\n\n\n\n<p>The display will also randomly show a message. The text can be adjusted in the variable message.<\/p>\n\n\n\n<p>The DFPlayer Mini is used for the sound output. It plays MP3 and WAV files from an SD card. The SD card must be formatted in the FAT16 or FAT32 file system. In addition, the files must be in the folder \u201c01\u201d and the file names must be sequentially named 001.mp3, 002.mp3, 003.mp3, and so on. As mentioned, WAV files may also be used: 001.mp3, 002.wav, 003.mp3 \u2026<\/p>\n\n\n\n<p>Sample files can be downloaded here:<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-primary\"><a class=\"wp-block-button__link\" href=\"https:\/\/starthardware.org\/wp-content\/uploads\/2021\/03\/01.zip\">Download MP3 files<\/a><\/div>\n<\/div>\n\n\n\n<p>Further info about the DF-Player on this page: <a href=\"https:\/\/starthardware.org\/en\/dfplayer-mini-mp3-player-for-arduino\/\" target=\"_blank\" rel=\"noreferrer noopener\">DFPlayer Mini-MP3-Player for Arduino<\/a>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">int flickerTimeLights = 1000;                   \/\/ the higher the value, the more the fluorescent tubes flicker when switched on\nint flickerSpeed = 100;                         \/\/ flickering speed of the fluorescent tubes\nint announcementChangeMin = 2000;               \/\/ announcement change every x milliseconds\nint announcementChangeVariableTime  = 3000;     \/\/ the announcement change varies by this value (milliseconds)\n\nint mp3Count  = 10;                             \/\/ amount of MP3 files on the SD card\nint mp3Duration[] = {16,16,15,17,17,18,19,18,19,9}; \/\/ duration of MP3 files in seconds\nint mp3Likelihood = 20;                         \/\/ likelihood of MP3s being played, 10 often, 100 rarely\nint volume = 10;                                \/\/ volume of the DFPlayer (0 \u2013 30);\n\n\/* Announcements *\/\nint numberOfAnnouncements = 6;                  \/\/ Must be as large as the number of announcement texts from the array textSegments\n\nconst char* textSegments[6][7] = {\n  {\"12\", \"\", \"Train passing through!\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Hannover Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Berlin Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Dresden Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Leipzig Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Hamburg Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"}\n};\n\nconst char* message[] = {\n  \"Due to a signal fault \",\n  \"the ICE100 will unfortunately have approx. 25 minutes delay. \",\n  \"We appreciate your understanding.\"\n};<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Code for the RaylFX Train Station Module<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Libraries<\/h3>\n\n\n\n<p>This project requires the <em>SSD1306Ascii <\/em>library from <em>Bill Greiman<\/em>. You can add it by searching for &#8220;SSD1306Ascii&#8221; in the Arduino <em>menu &gt; Sketch &gt; Include Library &gt; Manage Libraries<\/em> and installing the current version..<\/p>\n\n\n\n<p>In addition, the library <em>DFRobotDFPlayerMini<\/em> from <em>DFRobot <\/em>is used. You can also install this library via <em>Manage Libraries<\/em>. Here you can simply search for <em>dfplayer<\/em>.<\/p>\n\n\n\n<p>When uploading you have to make sure that the correct board is selected in the Arduino menu. To do this, &#8220;ATmega328P (Old Bootlaoder)&#8221; must also be selected in the Processor subitem of the Tools menu. Otherwise you can simply copy the following program code with the above mentioned changes and load it onto the Arduino nano.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;Wire.h>\n#include \"SSD1306Ascii.h\"\n#include \"SSD1306AsciiWire.h\"\n#include \"SoftwareSerial.h\"              \/\/ required for the DFPlayer\n#include \"DFRobotDFPlayerMini.h\"         \/\/ required for the DFPlayer\n\n\/*\n     Rayl-FX Train Station\n     StartHardware.org\/en\n*\/\n\n\/* ***** ***** Settings ***** ***** ***** *****  ***** ***** ***** *****  ***** ***** ***** ***** *\/\n\nint flickerTimeLights = 1000;                   \/\/ the higher the value, the more the fluorescent tubes flicker when switched on\nint flickerSpeed = 100;                         \/\/ flickering speed of the fluorescent tubes\nint announcementChangeMin = 2000;               \/\/ announcement change every x milliseconds\nint announcementChangeVariableTime  = 3000;     \/\/ the announcement change varies by this value (milliseconds)\n\nint mp3Count  = 10;                             \/\/ amount of MP3 files on the SD card\nint mp3Duration[] = {16,16,15,17,17,18,19,18,19,9}; \/\/ duration of MP3 files in seconds\nint mp3Likelihood = 20;                         \/\/ likelihood of MP3s being played, 10 often, 100 rarely\nint volume = 10;                                \/\/ volume of the DFPlayer (0 \u2013 30);\n\n\/* Announcements *\/\nint numberOfAnnouncements = 6;                  \/\/ Must be as large as the number of announcement texts from the array textSegments\n\nconst char* textSegments[6][7] = {\n  {\"12\", \"\", \"Train passing through!\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Hannover Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Berlin Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Dresden Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Leipzig Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"},\n  {\"12\", \"Leipzig Central - Halle (Saale)\", \"Hamburg Central\", \"RB31\", \"RB31\", \"Elsterw-Biehal\", \"from Coswig (b. Dresden)\"}\n};\n\nconst char* message[] = {\n  \"Due to a signal fault \",\n  \"the ICE100 will unfortunately have approx. 25 minutes delay. \",\n  \"We appreciate your understanding.\"\n};\n\n\/* ***** ***** From here begins the program code, which does not need to be adjusted ***** ***** ***** ***** *\/\n\/\/ 0X3C+SA0 - 0x3C or 0x3D\n#define I2C_ADDRESS 0x3C\nuint32_t tickTime = 0;\nint tickerPosition = 0;\n#define RTN_CHECK 1\n\nint fluorescentTubesPins[9] = {4, 5, 6, 7, 8, 9, 10, 11, 12};\n\n\/* Memory Variables *\/\nint fluorescentTubesState[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1};\nTickerState state;          \/\/ stores the current text pointer of the OLED ticker\nint thereIsDelay = 0;       \/\/ is determined at random; 1 = delay, 0 = no delay\nint announcementChangeVariableTimeAuxiliaryVariable = 0;\n\n\/* Timer Variables *\/\nlong fluorescentTubesTimer[9];\nlong announcementTimer;\n\n\/* Variables for the OLED *\/\nSSD1306AsciiWire oled;\n\n\/* Variables for the MP3 Player*\/\nlong soundTimer = 0;                     \/\/ timer of the DFPlayer\nlong soundTimeout = 0;                   \/\/ stores the playing time of the current MP3\nint soundState = 0;                      \/\/ state of the DFPlayers\n\nint soundRandom;\nint theSound;\nint soundPlaying = false;\n\nSoftwareSerial mySoftwareSerial(3, 2);   \/\/ RX, TX for the DFPlayer\nDFRobotDFPlayerMini myDFPlayer;          \/\/ DFPlayer object\n\n\/* Variables from the control module to determine the time of day *\/\nboolean receive = false;\nboolean receiveStarted = false;\nint receiveTimeout = 10;\nlong receiveTimer = 0;\nint receivedTime = 0;\nint receivePulse = 0;\nint lastReceivePulse = 0;\nint receivePin = 17;\nint myTime = 8;\nint myMinutes = 0;\nlong lastTimeSignal;\nint timeToHour;\n\n#define PAYLOAD_SIZE 2                          \/\/ mandatory for communication with master-module\nint timeOfDay = 0;                              \/\/ stores timeOfDay of master-module (0 and 255)\nbyte nodePayload[PAYLOAD_SIZE];                 \/\/ temporarily stores data of master-module\n\nvoid setup() {\n  Serial.begin(115200);                         \/\/ starts the serial communication\n  Wire.begin();                                 \/\/ I2C connection to OLED\n  Wire.setClock(400000L);                       \/\/ I2C connection to OLED\n  mySoftwareSerial.begin(9600);                 \/\/ starts the serial communication for the DFPlayer\n  oled.begin(&amp;Adafruit128x64, I2C_ADDRESS);     \/\/ start of the OLED\n\n\n\n  for (int i = 0; i &lt; 9; i++) {\n    pinMode(fluorescentTubesPins[i], OUTPUT);\n    digitalWrite(fluorescentTubesPins[i], HIGH);\n  }\n  randomSeed(A2);\n  oled.tickerInit(&amp;state, Adafruit5x7, 0, false, 27, 100);    \/\/ ticker for the departure display\n  drawInfo(1);\n\n  \/* DFPlayer Setup *\/\n  Serial.println(F(\"Initializing DFPlayer ... \"));\n  if (!myDFPlayer.begin(mySoftwareSerial)) {  \/\/ use softwareSerial to communicate with the DFPlayer\n    Serial.println(F(\"Fehler: Pr\u00fcfe Verbindung zum DFPlayer und SD-Karte\"));\n    \/*while (true) {\n      delay(0); \/\/ Code to compatible with ESP8266 watch dog.\n      }*\/\n  }\n  Serial.println(F(\"DFPlayer Mini online.\"));\n  myDFPlayer.volume(volume);       \/\/ volume is assigned\n}\n\nvoid loop() {\n\n  receiveFunction();                \/\/ execute instructions for reception\n  \n  if (receiveStarted == false) {      \/\/ if no data is currently being received:\n    \n    if (myTime > 22) {                \/\/ ***** late evening *****\n      fluorescentTubesOn();           \/\/ turn on fluorescent tubes\n      soundOn();                      \/\/ turn on sound\n      \n    } else if (myTime > 18) {         \/\/ ***** evening *****\n      fluorescentTubesOn();           \/\/ turn on fluorescent tubes\n      soundOn();                      \/\/ turn on sound\n      \n    } else if (myTime > 12) {         \/\/ ***** noon *****\n      fluorescentTubesOff();          \/\/ turn off fluorescent tubes\n      soundOn();                      \/\/ turn on sound\n      \n    } else if (myTime > 9) {          \/\/ ***** forenoon *****\n      fluorescentTubesOff();          \/\/ turn off fluorescent tubes\n      soundOn();                      \/\/ turn on sound\n      \n    } else if (myTime > 7) {          \/\/ ***** morning *****\n      fluorescentTubesOff();          \/\/ turn on fluorescent tubes\n      soundOn();                      \/\/ turn on sound\n      \n    } else if (myTime > 0) {          \/\/ ***** night *****\n      fluorescentTubesOn();           \/\/ turn on fluorescent tubes\n      soundOff();                     \/\/ turn off sound\n    }\n    if (myMinutes &lt; 40) departureDisplay();\n  }\n}\n\nvoid departureDisplay() {\n  int i;\n  if (announcementTimer + announcementChangeMin + announcementChangeVariableTimeAuxiliaryVariable &lt; millis()) { \/\/ the second part prevents that a display change blocks the reception of the time signal\n    announcementTimer = millis();\n    i = random(numberOfAnnouncements);\n    drawInfo(i);\n    thereIsDelay = random(2);\n    announcementChangeVariableTimeAuxiliaryVariable = random(announcementChangeVariableTime );\n  }\n  if ((thereIsDelay > 0) &amp;&amp; (i != 0)) {\n    if (tickTime &lt;= millis()) {\n      tickTime = millis() + 30;\n      oled.setInvertMode(1);\n      int8_t rtn = oled.tickerTick(&amp;state);\n      if (rtn &lt;= RTN_CHECK) {\n\n        oled.tickerText(&amp;state, message[(tickerPosition++) % 3]);\n      }\n    }\n  }\n}\n\nvoid drawInfo(int i) {      \/\/ OLED output\n  oled.clear();\n  oled.setInvertMode(0);\n\n  oled.setCursor(0 , 0);\n  oled.setFont(Callibri15);\n  oled.println(textSegments[i][0]);\n  oled.clearToEOL();\n\n  oled.setCursor(104 , 0);\n  oled.setFont(Callibri10);\n  oled.println(makeTime());\n  oled.clearToEOL();\n\n  oled.setFont(Callibri10);\n  oled.setCursor(27 , 1);\n  oled.println(textSegments[i][1]);\n  oled.setFont(Callibri14);\n  oled.setCursor(27 , 2);\n  oled.println(textSegments[i][2]);\n\n  oled.setFont(Callibri10);\n  oled.setCursor(0 , 5);\n  oled.println(makeTime1());\n  oled.setCursor(0 , 6);\n  oled.println(makeTime2());\n\n  oled.setCursor(27 , 5);\n  oled.println(textSegments[i][3]);\n  oled.setCursor(27 , 6);\n  oled.println(textSegments[i][4]);\n\n  oled.setCursor(54 , 5);\n  oled.println(textSegments[i][5]);\n  oled.setCursor(54 , 6);\n  oled.println(textSegments[i][6]);\n}\n\nString makeTime() {\n  String myTimeString = \"\";\n  int myHoursSub = myTime;\n  int myMinutesSub = myMinutes;\n  if (myHoursSub &lt; 10) myTimeString = \" \" + String(myHoursSub);\n  else myTimeString = String(myHoursSub);\n  if (myMinutesSub &lt; 10) myTimeString += \":0\" + String(myMinutesSub);\n  else myTimeString += \":\" + String(myMinutesSub);\n  return myTimeString;\n}\n\n\nString makeTime1() {\n  \/\/ next train\n  String myTimeString = \"\";\n  int myHoursSub = myTime;\n  int myMinutesSub = myMinutes;\n\n  \/\/ int myMinutesSub1=random(30);\n  if (myMinutesSub > 29) {\n    if (myHoursSub > 22) myHoursSub = 0;\n    else myHoursSub++;\n  } else {\n    myMinutesSub += 30;\n  }\n\n  if (myHoursSub &lt; 10) myTimeString = \" \" + String(myHoursSub);\n  else myTimeString = String(myHoursSub);\n  if (myMinutesSub &lt; 10) myTimeString += \":0\" + String(myMinutesSub);\n  else myTimeString += \":\" + String(myMinutesSub);\n  return myTimeString;\n}\n\n\nString makeTime2() {\n  \/\/ train after the next train\n  String myTimeString = \"\";\n  int myHoursSub = myTime;\n  int myMinutesSub = myMinutes;\n\n  if (myHoursSub >= 23) myHoursSub = 0;\n  else myHoursSub++;\n\n  if (myHoursSub &lt; 10) myTimeString = \" \" + String(myHoursSub);\n  else myTimeString = String(myHoursSub);\n  if (myMinutesSub &lt; 10) myTimeString += \":0\" + String(myMinutesSub);\n  else myTimeString += \":\" + String(myMinutesSub);\n  return myTimeString;\n}\n\nvoid fluorescentTubesOn() {\n\n  for (int i = 0; i &lt; 9; i++) {\n    if (random(flickerTimeLights) == 0) fluorescentTubesState[i] = 0;\n    if (fluorescentTubesState[i] != 0) {                        \/\/ when the fluorescent tube is not switched on\n      if (fluorescentTubesState[i] + fluorescentTubesTimer[i] &lt; millis()) {\n        fluorescentTubesState[i] = random(flickerSpeed) + 20;   \/\/ creates a timeout variable\n        fluorescentTubesTimer[i] = millis();\n        int myOutput = random(2);\n        digitalWrite(fluorescentTubesPins[i], myOutput);\n      }\n    } else {\n      digitalWrite(fluorescentTubesPins[i], 0);\n    }\n  }\n}\n\nvoid fluorescentTubesOff() {\n  for (int i = 0; i &lt; 9; i++) {\n      fluorescentTubesState[i]=1;\n      digitalWrite(fluorescentTubesPins[i], HIGH);\n  }\n  \n  \/*if (random(switchOffProbability) == 1) {   \/\/  switching on the fluorescent tubes at random\n    int thePin = random(10);\n    digitalWrite(fluorescentTubesPins[thePin], HIGH);\n    fluorescentTubesState[thePin] = 0;\n  }*\/\n}\n\nvoid soundOn() {\n  switch (soundState) {\n    case 0:\n      soundRandom = random(mp3Likelihood);\n      if (soundRandom &lt; 1) {\n        soundState = 1;\n        theSound = random(mp3Count ) + 1;\n        soundTimer = millis();\n        soundTimeout = mp3Duration[theSound - 1] * 1000;\n        Serial.print(\"Playsound: \\t\\t\\t\"); Serial.print(theSound); Serial.print(\"\\t\\t\\t\"); Serial.println(soundTimeout);\n        myDFPlayer.playFolder(1, theSound); \/\/play specific mp3 in SD:\/15\/004.mp3; Folder Name(1~99); File Name(1~255)\n        soundPlaying = true;\n      } else {\n        soundTimer = millis();\n        soundTimeout = 500;\n        soundState = 1;\n      }\n      break;\n    case 1:\n      if (soundTimer + soundTimeout &lt; millis()) {\n        myDFPlayer.pause();\n        soundPlaying = false;\n        soundState = 0;\n      }\n      break;\n  }\n}\n\n\nvoid soundOff() {\n  if (soundPlaying == true) {\n    Serial.println(soundPlaying);\n    myDFPlayer.pause();\n    soundPlaying = false;\n  }\n}\n\nvoid receiveFunction() {                      \/\/ receives time of day from control module\n  receivePulse = digitalRead(receivePin);     \/\/ read out the receive pin\n\n  if ((receiveTimer + receiveTimeout &lt; millis()) &amp;&amp; (receiveStarted == true)) {\n    \/\/ on timeout and active reception\n    receiveStarted = false;                   \/\/ end active reception\n    myTime = receivedTime - 1;                \/\/ store received time\n    receivedTime = 0;                         \/\/ reset the auxiliary variable for time reception\n\n    timeToHour = millis() - lastTimeSignal;\n    lastTimeSignal = millis();\n\n  }\n\n  \/\/ if a pulse is detected at the receive pin that was not there before\n  if ((receivePulse == 0) &amp;&amp; (lastReceivePulse == 1)) {\n    receiveTimer = millis();                              \/\/ restart timer\n    if (receiveStarted == false) receiveStarted = true;   \/\/ start active reception, if not already done\n    receivedTime++;                                       \/\/ there was a pulse, so increase the auxiliary variable to receive time\n  }\n  lastReceivePulse = receivePulse;                        \/\/ remember current state at pin for next pass\n\n  if (receiveStarted == false) {\n    if (millis() % 100 &lt; 2) {\n      int myNewMinutes = map(millis() - lastTimeSignal, 0, timeToHour, 0, 59);\n      myNewMinutes = constrain(myNewMinutes, 0, 59);\n\n      if (myNewMinutes != myMinutes) {\n        Serial.print(myTime); Serial.print(\":\"); Serial.print(myMinutes);\n        Serial.print(\"\\t\"); Serial.println(myTime);\n      }\n\n      myMinutes = myNewMinutes;\n    }\n  }\n}<\/pre>\n\n\n<ul class=\"wp-block-latest-posts__list is-grid columns-3 wp-block-latest-posts\"><\/ul>\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-primary\"><a class=\"wp-block-button__link\" href=\"https:\/\/starthardware.org\/en\/category\/projects\/arduino-projects\/raylfx\/\" target=\"_blank\" rel=\"noreferrer noopener\">View all RaylFX modules \u00bb<\/a><\/div>\n<\/div>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>This module of the RaylFX system controls an Arduino train station for the model railway. The functions include: OLED-Departure display with changing content Sound-module with verbal announcements Train station lighting with fluorescent tube switch on effect Wiring Diagram D2, D3: DFPlayer MP3 module D4 \u2013 D12: LEDs as fluorescent tubes A3: connection of the time&hellip;&nbsp;<a href=\"https:\/\/starthardware.org\/en\/raylfx-train-station\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">RaylFX \u2013 Train Station<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":749,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[5,9],"tags":[],"class_list":["post-746","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino-projects","category-raylfx"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>RaylFX \u2013 Train Station<\/title>\n<meta name=\"description\" content=\"RaylFX \u2013 Here you will learn how to build an Arduino train station for your model railway. Complete with MP3 module, OLED display LEDs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/starthardware.org\/en\/raylfx-train-station\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"RaylFX \u2013 Train Station\" \/>\n<meta property=\"og:description\" content=\"RaylFX \u2013 Here you will learn how to build an Arduino train station for your model railway. Complete with MP3 module, OLED display LEDs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/starthardware.org\/en\/raylfx-train-station\/\" \/>\n<meta property=\"og:site_name\" content=\"StartHardware - Tutorials for Arduino\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-26T23:04:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-28T08:58:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-train-station-oled-title2-930x620-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"930\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"David Hermann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/starthardware.org\/en\/#website\",\"url\":\"https:\/\/starthardware.org\/en\/\",\"name\":\"StartHardware - Tutorials for Arduino\",\"description\":\"Arduino, Electronics, Fun\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/starthardware.org\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-train-station\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-train-station-oled-title2-930x620-1.jpg\",\"contentUrl\":\"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-train-station-oled-title2-930x620-1.jpg\",\"width\":930,\"height\":620,\"caption\":\"Arduino Train Station RaylFX OLED\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-train-station\/#webpage\",\"url\":\"https:\/\/starthardware.org\/en\/raylfx-train-station\/\",\"name\":\"RaylFX \u2013 Train Station\",\"isPartOf\":{\"@id\":\"https:\/\/starthardware.org\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-train-station\/#primaryimage\"},\"datePublished\":\"2021-03-26T23:04:49+00:00\",\"dateModified\":\"2021-03-28T08:58:47+00:00\",\"author\":{\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c\"},\"description\":\"RaylFX \u2013 Here you will learn how to build an Arduino train station for your model railway. Complete with MP3 module, OLED display LEDs.\",\"breadcrumb\":{\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-train-station\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/starthardware.org\/en\/raylfx-train-station\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/starthardware.org\/en\/raylfx-train-station\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/starthardware.org\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"RaylFX \u2013 Train Station\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c\",\"name\":\"David Hermann\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/starthardware.org\/en\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g\",\"caption\":\"David Hermann\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"RaylFX \u2013 Train Station","description":"RaylFX \u2013 Here you will learn how to build an Arduino train station for your model railway. Complete with MP3 module, OLED display LEDs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/starthardware.org\/en\/raylfx-train-station\/","og_locale":"en_US","og_type":"article","og_title":"RaylFX \u2013 Train Station","og_description":"RaylFX \u2013 Here you will learn how to build an Arduino train station for your model railway. Complete with MP3 module, OLED display LEDs.","og_url":"https:\/\/starthardware.org\/en\/raylfx-train-station\/","og_site_name":"StartHardware - Tutorials for Arduino","article_published_time":"2021-03-26T23:04:49+00:00","article_modified_time":"2021-03-28T08:58:47+00:00","og_image":[{"width":930,"height":620,"url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-train-station-oled-title2-930x620-1.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"David Hermann","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/starthardware.org\/en\/#website","url":"https:\/\/starthardware.org\/en\/","name":"StartHardware - Tutorials for Arduino","description":"Arduino, Electronics, Fun","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/starthardware.org\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/raylfx-train-station\/#primaryimage","inLanguage":"en-US","url":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-train-station-oled-title2-930x620-1.jpg","contentUrl":"https:\/\/starthardware.org\/en\/wp-content\/uploads\/2021\/03\/raylfx-arduino-model-train-station-oled-title2-930x620-1.jpg","width":930,"height":620,"caption":"Arduino Train Station RaylFX OLED"},{"@type":"WebPage","@id":"https:\/\/starthardware.org\/en\/raylfx-train-station\/#webpage","url":"https:\/\/starthardware.org\/en\/raylfx-train-station\/","name":"RaylFX \u2013 Train Station","isPartOf":{"@id":"https:\/\/starthardware.org\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/starthardware.org\/en\/raylfx-train-station\/#primaryimage"},"datePublished":"2021-03-26T23:04:49+00:00","dateModified":"2021-03-28T08:58:47+00:00","author":{"@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c"},"description":"RaylFX \u2013 Here you will learn how to build an Arduino train station for your model railway. Complete with MP3 module, OLED display LEDs.","breadcrumb":{"@id":"https:\/\/starthardware.org\/en\/raylfx-train-station\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/starthardware.org\/en\/raylfx-train-station\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/starthardware.org\/en\/raylfx-train-station\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/starthardware.org\/en\/"},{"@type":"ListItem","position":2,"name":"RaylFX \u2013 Train Station"}]},{"@type":"Person","@id":"https:\/\/starthardware.org\/en\/#\/schema\/person\/37dd49804e351d0045589790d695d99c","name":"David Hermann","image":{"@type":"ImageObject","@id":"https:\/\/starthardware.org\/en\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c1f55f9c9addf2633dc5513f65e57c6b11de8c1d05cab7a65be1e402233d543?s=96&d=mm&r=g","caption":"David Hermann"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/comments?post=746"}],"version-history":[{"count":22,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/746\/revisions"}],"predecessor-version":[{"id":831,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/posts\/746\/revisions\/831"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media\/749"}],"wp:attachment":[{"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/media?parent=746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/categories?post=746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/starthardware.org\/en\/wp-json\/wp\/v2\/tags?post=746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}