the led flashes for 30 seconds

how to make if the button is pressed then the led will blink, if the button is not pressed then the LED will flash for 30 seconds?

You posted this in Gigs and Collaborations. Are you prepared to pay?

Do you know how to read a button? Do you know how to blink a led?

You might want to look at blink-without-delay to understand how to use millis() for timing.

To the OP, perhaps you meant to post this in Project Guidance? This just doesn't seem like a project that will get a lot of professional programmers excited.

Unless you are paying tip-top dollar that is! ;)

I think he posted it to incorrect subphorum.

Hi aris,

That’s pretty straightforward. Do you have a start, or are you just looking for a quick sketch? Folks here can help in either case.

It’s not clear what you want. It appears that you want this:

If the button is pressed, you want the LED to flash once. If not you want it to flash on and off for 30 seconds.

How long do you want to wait before it decides that the button wasn’t pressed before it starts flashing?

Do you want to do this once and halt, or do this in a loop that repeats forever? What happens after the button-press flash and what happens after the 30 seconds of flashing?


  1. don’t even think about using delay() to solve this.
  2. If the button is pressed, start a timer. Something like:
    uint32_t flashTimer = 0 ;  // global

    loop() {
       . . . 
       if ( <button pressed > )  flashTimer  = millis() ;
       . . . 
  1. until the timer expires, flash the led (also in the loop) ;
     if ( millis() - flashTimer < 30000UL ) {  // 30 seconds
           // flash led here