Make Storm lightning delay or millis ?

Hi there,

I'm playing a thunderstorm sound with an Arduino with ethernet module and MP3 module.

Now, I would like to add some lighting and I would like to program the exact time when it will flash. -> for exemple "afer 3 second, then after 5 second, etc...

I know that using delay is not a good thing if I want to be able to contact my arduino from ethernet but it's seems hard to use millis in that case.

What would you recommend ? using a second arduino ?

thanks !

neorobot: it's seems hard to use millis in that case.

Why do you think it's hard to use millis in that case?

Hi Pert, Thanks for your answer !

If we imagine that a "big lighting" is composed of 4 or 5 "little flash light", it means that I will have to:

1) flash 2) wait (10ms for example) 3)Flash 4) wait (5ms for example) 5) Flash 6) wait (5ms for example) 7) Flash 8) wait (10000ms)

This is for only one big lighting. The total will be 50 or 60.

I dont understand how to organize my code to place all the delays.

Thanks !

You can use the code from File > Examples > 02.BlinkWithoutDelay. You only need to change the value of interval each time. You could use random() to set the intervals to give it some variation:

Do you want it with specific delays and not random ? Then you can put the timing in a table. Try my millis_rhythm.ino example and see what it does.

Thanks Pert ! I had already seen the demo but had some diffuculties with the "big lighting" and the "little lighting", if you see the difference lol :)

Koepel, that's really good, having a table with all the delays is a very good idea i'm not sure that 160 "on - 200 "off" is really turned on during 40ms, but the idea is very good.

I think I'll try in that way.

My example turns the led on for 160 ms and then the led is off for 200 ms, then on for 140 ms, then off for 200 ms.

You have to change the sketch, if you want to:

  • specific timing where each number is the milliseconds from the start
  • start with a delay
  • stop at the end of the table

@koepel Ow Ok I see, Yes that's exactly what I need!

I just have to create a sequence with some little flashes, and make an OFF time bigger to make another "lighting".

I have tested it, that's perfect, time to sync it with the sound now ;)

Thank you !

When you open the mp3-file in Audacity, then you can directly write in the sketch the time (in milliseconds) and the duration. You could make an array of unsigned long, or a struct with a unsigned long and a unsigned integer. If you use an Arduino Uno, then I would put that table in PROGMEM. The time in milliseconds can be since the start of the file, or since the start of the lightning. Choose what is the easiest for you, and then adapt the sketch to use it in that way.

I hope you are not already trying to write the relative time in a table, so that when you make one thing larger then everything shifts and must be tuned again to the right timing.