Double Blink and delay for 1000 MS without delay()

thnks Boss...

If you want to learn Arduino and its programming, then follow SSS Strategy. SSS stands for Small Start Strategy approach; where, you begin with a basic (simple and elementary) hardware and associated software/cdoes and make it working. After that you add incremental amount of hardware and code, test it and so on until the project is completed.

2 Likes

Thanks.. I know Electronics. and basic coding in Arduino.. But the Algorithem is bit difficult.. Thnks Again Boss. Pls suggest some good site for reading.

Pick up example one-by-one from this link of Arduino examples and prcatice it. After that ask question to the Forum members referring to your sketch for clarification and explanation.

Look at my sketch of Post-9, which I have taken from Arduino Examples and added few lines at the appropriate places to make a creative job that is your brain child. (Interesting that the last off-time of the last blink will be different from the previous off-time which can be done fantastically using "Blink Without Delay" strategy!)

1 Like

Hello
I´ve found and modifyed this sketch found in my sketch box.

// BLOCK COMMENT
// Attention: This sketch contains C++ elements.
// https://www.learncpp.com/cpp-tutorial/
// https://forum.arduino.cc/t/double-blink-and-delay-for-1000-ms-without-delay/904431/3
#define ProjectName "Double Blink and delay for 1000 MS without delay()"
// CONSTANT DEFINITION
// you may need to change these constants to your hardware and needs.
constexpr byte Output_[] {2};		// port pin o---|220|---|LED|--- GND.
// VARIABLE DECLARATION AND DEFINTION
enum {One};
unsigned long currentTime;
struct TIMER {
  unsigned long duration;
  unsigned long stamp;
};
TIMER flash{1000, 0};
struct FLASHER {
  bool state_;
  unsigned long duration;
} flasher [] {
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 50},
  {true, 50},
  {false, 1000},
};
// FUNCTIONS
bool checkTimer(TIMER & time_) {  // generic time handler using TIME struct
  if (currentTime - time_.stamp >= time_.duration ) {
    time_.stamp = currentTime;
    return true;
  } else return false;
}
void setup() {
  Serial.begin(9600);
  Serial.println(F("."));
  Serial.print(F("File   : ")), Serial.println(__FILE__);
  Serial.print(F("Date   : ")), Serial.println(__DATE__);
  Serial.print(F("Project: ")), Serial.println(ProjectName);
  pinMode (LED_BUILTIN, OUTPUT);
  for (auto Output : Output_) pinMode(Output, OUTPUT);
}
void loop () {
  currentTime = millis();
  digitalWrite(LED_BUILTIN, (currentTime / 500) % 2);
  if (checkTimer(flash)) {
    static int element = 0;
    digitalWrite(Output_[One], flasher[element].state_);
    flash.duration = flasher[element].duration;
    element++;
    element %= (sizeof(flasher) / sizeof(flasher[0]));
  }
}

Have a nice day and enjoy coding.

We expect to see some popular codes that talk what the @t_tuku wants. The OP wants 2 blinks (for example); where, the off-time of the last blink will be differenet from the off-time of the previous blinks. For example: The On/Off time for the first 11/2 blinks are 50 ms (for example) and the off-time for the last blink would be 1000 ms (for example). After that the precess repeats. The OP also wants that the sketch sould be created using "Blink Without Delay" approach.

1 Like

Hello
You are right.
The TO shall find how to configure the blink pattern he need.
That´s very easy to do.

1 Like

Do you think that someone has made an attempt in this thread to realize the OP's objective?

1 Like

yes, never give up.

1 Like

Yes, see post #21.

My only concern is, forgive me for repeating the same analogy I always seem to repeat: did we give a man a fish or did we help him to learn a little about how to fish for himself (or herself)?

The @t_tuku is just a beginner who needs solid working/tested example which he can follow to get a result and then learn codings through repeated exercise.

There are Members in this Forum who know whom to help to fish!

2 Likes

Do you know @t_tuku personally?

In Forum all are virtual figures.

1 Like

I changed it to if (counter == int(betweenDelay)/interval) counter = 0; // here betweenDela==1000ms

Ok but how could i make it auto change of above code if i wish to blink it three times.
it could be if(counter==0||counter==2||counter==4) .
But how to set it automatically with any c programme??

Yes.

Don't understand what you're asking.

like if we blink it twice we have to programme if(counter==0||counter==2). Right?

if we blink it thrice we have to programme if(counter==0||counter==2||counter==4). Right?

so how to automate it for input of number of blinking

Are you wanting to have the user input a thing and then do the blinky-thingy as per the user input?

we make a global variable like int noofBlink = 3;.

A simple start, if you understand this, you should be able to change noofBlinks. :slightly_smiling_face:

unsigned long timer, elapsed;
const int interval = 1000;
const byte led = LED_BUILTIN,
           onTime = 50;

void setup()
{
  pinMode(led,OUTPUT);
}

void loop()
{
  elapsed = millis() - timer;
  digitalWrite(led,elapsed < onTime // first blink
       // second blink
    || (elapsed > onTime * 2 && elapsed < onTime * 3));
  if(elapsed > interval)
    timer += interval;  // reset timer
}

how to set the code?