1 input operates up to 13 LEDs

Hi everybody I want to activate Arduino Nano from my GE plc. To connect one plc output to one Nano input & operate up to 13 LEDs from the Arduino. This should be done in "sort of" Quick cycling serial communication code. If a LED is turned on by the plc in one of the HI pulses, it has to stay so (hold) & will be turned off only by an OFF pulls in one of the next cycles. And vice versa. I'm sure someone has already done that. How do I find it? If it helps, I know to do that with "ladder diagram" but can not write C ++. Help pleas. thanks Aharonzo

So far, we have virtually no information on your requirements.

You have to do a better job of specifying all the details and protocols. That said, if you know all the details and protocols, the job is almost finished. :D

Hello everyone. I think it should work that way: 1. Input TX1 gos HI for one second, it means the count begins. 2. Arduino counts 1 to 13 and stops. Eeach count is half a second long. This is the cycle. 3. Each count corresponds to one output. 4. Each count for (example count 4) that finds the input TX1 HI, the corresponding output (D4) turns ON & remains on, till the next cycle. 5. At the end of cycle (count 13) counting stops, waiting for the 1 sec' pulse from TX1 to start over. 6. If the input TX1 in next cycle at this count (count 4) is HI, the output will remain on. If not, it will turns off. And so on.............

I/O list:

TX1=input count 1 > RX0=output to led1 count 2 > D2=output to led2 count 3 > D3=output to led3 " " " count 13 > D13=output to led13

Here is something to get you started.

unsigned long inputStart = 0;
unsigned long inputPeriod = 1000;
unsigned long ledStart = 0;
unsigned long ledPeriod = 500;
const byte ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15};
const byte inputPin = A0;
byte inputState;
byte previousInputState;
boolean waiting = false;

void setup()
{
  Serial.begin(115200);
  pinMode(A0, INPUT_PULLUP);
  for (int p = 0; p < 13; p++)
  {
    pinMode(ledPins[p], OUTPUT);
  }
}

void loop()
{
  inputState = digitalRead(inputPin);
  if (inputState == HIGH)
  {
    waiting = false;  //button has been released or is not pressed
  }
  if (inputState == LOW && previousInputState == HIGH)
  {
    inputStart = millis();  //button has been pressed.  Start waiting
    waiting = true;
  }
  if (waiting && millis() - inputStart >= inputPeriod)
  {
    Serial.println("Pressed for 1 second");  //waited for 1 second
    waiting = false;
    showLeds();    //time for action
  }
  previousInputState = inputState;    //save the input state for next time round loop()
}

void showLeds()
{
  byte currentLed = 0;
  ledStart = millis();    //save the start time for this LED
  byte on = false;
  while (currentLed < 13)
  {
    if (!on)
    {
      digitalWrite(ledPins[currentLed], HIGH);  //turn the LED on
      Serial.print("pin ");
      Serial.print(ledPins[currentLed]);
      Serial.println(" turned on");
      on = true;
    }
    if (millis() - ledStart >= ledPeriod)  //if 500 milliseconds has passed
    {
      digitalWrite(ledPins[currentLed], LOW);  //turn the LED off
      Serial.print("pin ");
      Serial.print(ledPins[currentLed]);
      Serial.println(" turned off");
      currentLed++;      //next LED
      ledStart = millis();   //save the start time for this LED
      on = false;
    }
  }
}

NOTES
I do not have 13 LEDs connected so I used Serial.print to monitor what is going on
You need to put your LED pin number in the ledPins array
I suggest that you avoid using pins D0 and D1 as they are used by the serial interface which you can use for debugging
I don’t understand this from your explanation

  1. If the input TX1 in next cycle at this count (count 4) is HI, the output will remain on. If not, it will turns off.

Thanks UKHeliBob. I am very new in this field of Arduino. I am very good at Hardware and have decades of experience in power, control & diferent plc’s programing, but have never done anything on Arduino or C++. What you said about D1 & D0 is very logical, thank you. I still do not know how to do monitoring. I’ll have to read a bit and learn how to do it. Meanwhile my wife is hospitalized and I do not know when I’ll have the time to continue working on with my idea. Besides all that, I’m 71 years old and learning new things is hard for me, not like it was 30 years ago. I’m sure I’ll need more help later, in the meantime I will use what you have given me and see where it goes to. At the end of all, I’ll even send you and all a photo of the finished product. In the meantime, thanks again and Goodby.

I still do not know how to do monitoring.

The Arduino environment is not very good for debugging. About the best that you can do is to write to the serial monitor as I did in my code. It is useful to know where in the program you are and the value of variables at that stage.

Best wished to your wife. Come back to this and ask questions as and when you can.

Thanks UKHeliBob for good wishes. From the little I understood, in the code you wrote, I see that U used the first analog input A0 as the activator. This is smart thinking then allows 1 more LED. Which means I can run 12 LEDs and leave the 0 and 1 for monitoring. And maybe after everything will work as needed, I can use also on pins 1-0 and put on them 2 more LED's. We'll see what unfolds.

Using the analogue pins (A0 to A5) as digital pins (input or output) means that you can use pins 2 to 13 (12 pins) and A0 to A5 (6 pins), which makes a total of 18 digital pins, without using pins 0 and 1 at all.