LED's to Blink @ Input Cycle time simultaneously with Different LED On time

Hi ! I am a starter & would like program for the following requirement.

I want to give Four Inputs -

  1. Rate (Cycle Time) at which the Blinking Starts ( All LED's to Start together for every Cycle Start time)

  2. Different LED ON Times for 3 LED's in Seconds. This time will NOT Be Greater than the Cycle time set.

Eg.: Say Rate (Cycle Time) is Blink every 2 Seconds, With the ON Time for LED-1 = 0.5 Sec,
LED-2 = 1 Sec & LED-3 = 1.2 Sec. Here the ON time of any LED is NOT >= the Cycle time of 2 Sec.

Result Expected = All 3 LED's Should turn ON at Once at each Cycle time of 2 Seconds --> The LED-1 to
be ON for 0.5 Sec & turn off, stay off till next cycle time, LED-2 to be ON for 1 Sec & turn off, stay off till next cycle time arrives, LED-3 to be ON for 1.2 Sec & turn off, stay off till next cycle time.
At Next Cycle time ( At end of 2 Seconds ) All three LED's should repeat the same sequence in loop.

Want to connect 4x4 Keyboard & 16x2 LCD for setting.

Please help...

To begin, connect only your 4 LEDs but not the keypad and LCD. Write a simple sketch to switch your LEDs on and off as you described in your example. I would recommend avoiding use of the delay() function, because it will probably cause problems later when you add your keypad & LCD. Instead of delay(), use millis() for timing. I would also recommend to use arrays to hold the pin numbers of the LEDs, and the on-times of the LEDs.

Thanks a lot for your reply,

I have been trying using millis() but facing a problem - The first time all LEd's start simultaneously & keep up their On times but then later they keep on adding up their own times resulting in their own sequence.
I want all the LED's to go ON at the Cycle times only & turn OFF as per their own ON times set.

Please guide.. Sir, If you have something written up please let me know..

Thanks again

So you write the code that way. You have a cycle timeout that sets all the LEDs on and resets all the LED timeout counters. Then each LED waits out its cycle time and turns off when that time expires.

If you want to discuss code, then post the code you have used for criticism. Read the instructions (point 7) first on how to post the code.

Want to connect 4x4 Keyboard & 16x2 LCD for setting.

For setting what, the on-times and the cycle time? Guessing you want the user to type those times in and they display on the screen, or what?

But here's a sketch for the part you already described:

// this version doesn't use a keypad and lcd
// nor does it use arrays, which could make the code tidier

const byte led1 = 2;
const byte led2 = 3;
const byte led3 = 4;
const int led1Time = 500;
const int led2Time = 1000;
const int led3Time = 1200;

unsigned long cycleStartedAt;
int cycleTime = 2000;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
} //setup

void loop()
{
  if (millis() - cycleStartedAt >= (unsigned long) cycleTime)
  {
    cycleStartedAt = millis();
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
  }

  if (millis() - cycleStartedAt >= led1Time) digitalWrite(led1, LOW);
  if (millis() - cycleStartedAt >= led2Time) digitalWrite(led2, LOW);
  if (millis() - cycleStartedAt >= led3Time) digitalWrite(led3, LOW);
} //loop

Dear Paul__B Sir,

Thanks for your guidance, Its very helpful for me.

Dear Johann Sir,

Thanks for the code. It worked satisfactorily. I will work ahead to interface 4x4 Matrix Key board & LCD.