Go Down

Topic: the led flashes for 30 seconds (Read 352 times) previous topic - next topic

aris14

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?

sterretje

#1
Dec 21, 2018, 06:50 am Last Edit: Dec 21, 2018, 06:52 am by sterretje
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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

ChrisTenone

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! ;)
What, I need to say something else too?

martinius96

I think he posted it to incorrect subphorum.
Arduino and website programmer

patduino

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?

Pat.
There are 10 types of people in the world, those who understand binary, and those that don't.

6v6gt

1) don't even think about using delay() to solve this.
2) If the button is pressed, start a timer. Something like:

Code: [Select]
    uint32_t flashTimer = 0 ;  // global

    loop() {
       . . .
       if ( <button pressed > )  flashTimer  = millis() ;
       . . .
   }


3) until the timer expires, flash the led (also in the loop) ;

 
Code: [Select]
     if ( millis() - flashTimer < 30000UL ) {  // 30 seconds
           // flash led here
      }

Go Up