Pages: [1]   Go Down
Author Topic: one shot led blinking with delay  (Read 900 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi everyone, i am just a very beginner in arduino (only 3 days...!!!) and i speak a very poor english ( only 3 days too...smiley )
i have a little project which is the following. during a circus show i need some "TOP" to send the light "go"on my lighting desk, but sometimes i have to see some people to send the GO, but as you know, almost of time it is black in the venue, and so i can't see the people if they are in ready position to send the GO.. so here is my idea. i am going to install some push button (kind of switch) in all the place i can not see the people, and when they are ready ,they push the button, and that give me a signal of the a blinking led.

so, do to that, and start in arduino,  i baught the massimo banzi book " geting started with arduino" and i use the first workshop to make a LED switch ON and keep it ON after one push on the button. that work fine but my problem is: i would like the signal stay active in blinking mode during 3 second then switch off, without push an other time on the button. i tried to add some "delay(3000); { digitalwrite(LED, LOW) } after the if/ else content, but it doesn't work.. i guess it is a very simple thing to do , but i think i don't have the programming vibe...!!!

so this is the code where i am.. if someone can tell me what is the function to stop the loop mode, in oder to get only one blinking signal of 3 second, then wait for the next "push button" to get the signal 3 second, and so on....

#define LED 11 // patte pour la led en 12
#define BUTTON 6 // patte entrée pour le switch

int val = 0; // val sauve etat entree switch
int old_val = 0; // contient précendente valeur de val
int state = 0; // 0 = led eteinte , 1 = led allumee

void setup() {
  pinMode(LED, OUTPUT); // DEL sur sortie
  pinMode(BUTTON, INPUT); // bouton en entrée
}

void loop() {
  val = digitalRead(BUTTON); // lit et sauve l'entree du switch
  if ((val == HIGH) && (old_val == LOW)){
    state = 1 - state;
    delay(200);
  }
  old_val = val; // sauve ancienne valeur
  if (state == 1) {
    digitalWrite(LED, HIGH); // allume led
    delay(100);
    digitalWrite(LED, LOW); // eteint led
    delay(100);
  }
  else {
    digitalWrite(LED, LOW);
  }
  delay(3000) {
    digitalWrite(LED, LOW);
  }
 }
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3447
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd recommend posting in the French sub-forums, because I"m afraid your lack of experience with English is getting in the way here.

The only suggestion I have for what I think you may be looking to do is take a look at the Blink without Delay example.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't worry about your poor English, my French is probably worse!

1. When you post code, please press the # button and paste your code between the code tags that appear.

2. What I think you are trying to do is this: when the button is pressed, blink the LED for 3 seconds and then turn it off. Repeat when the button is pressed again. If that is correct, try this:

Code:
#define LED 11 // patte pour la led en 12
#define BUTTON 6 // patte entrée pour le switch

void setup() {
  pinMode(LED, OUTPUT); // DEL sur sortie
  pinMode(BUTTON, INPUT); // bouton en entrée
}

void loop()
{
  if (digitalRead(BUTTON))
  {
    for (int i = 0; i < 3; ++i)
    {
       digitalWrite(LED, HIGH);
       delay(500);
       digitalWrite(LED, LOW);
       delay(500);
    }
  }
}

I am assuming (based on your original code) that your push button is wired between the pin and Vcc, and you have a pulldown resistor between the pin and ground.
« Last Edit: November 25, 2012, 01:13:11 pm by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2927
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not knowing French is half the fun.

Also this statement makes no sense to me, I don't see how it could compile.

Code:
delay(3000) {
    digitalWrite(LED, LOW);
  }

However, the system will be totally unresponsive during the 3-sec delay, so you should start
to investigate how to do delays more efficiently, see the Arduino IDE

"File > Examples > 2.Digital > BlinkWithoutDelay" sketch.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi dc42, and thank you so much , it is exactly what i was looking for... it is my very beginning and i feel so stupid to ask help for some easy thing like this. by the way , the blink rythme was to slow, so i understand the relation between the delay time and the " for (int i = 0; i < 15; ++i) " and put the delay at 100 and i<15 to get more faster the blink.... but i still don't understand what is the real function of "for" and why we use "int" at this place and what is "i".. so many why why why.. anyway it work as i want...

so god save the queen, but YOU save my show... thanks !!!
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
god save the queen

it's not like everyone here is from England  smiley-razz
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 227
Posts: 6639
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

.... but i still don't understand what is the real function of "for" and why we use "int" at this place and what is "i".. so many why why why.. anyway it work as i want...

See http://arduino.cc/en/Reference/For.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Florida USA
Offline Offline
Newbie
*
Karma: 2
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I may not understand the posters need but the simplest thing would be just a 555 as a one shot and a blinking LED..
Not a good suggestion if trying to use Arduino's though.Seems like overkill to me.
jolphil
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is very similar to a 'ready state' system I build for similar circumstances: pitch dark stage with 24 dancers that are lit up with LEDs attached to their bodies.  Though mine's an RF based system.  Each dancer has a push button that rest at the very edge of their (long) sleeve so they can easily push it when they make a fist.  The RF signal gets picked up by the receiver at the console and an LED pertaining to that dancer goes on.  In my case however, the LED remains on till everyone's "checked in" and the show starts.  Once the music starts, the program starts running and the units on the dancers become receivers so they can receive instructions from the transmitter at the console.
Logged

Florida USA
Offline Offline
Newbie
*
Karma: 2
Posts: 44
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I will let you and or others to determine whether a simple circuit will work for you or not but here is one of many,many application notes for the popular 555 timer you can look over. Simple low cost components can be purchased from even Radio Shack or your electronics store.My guess is you would need a plug in walwart PS of about 9volts DC a 5volt 3 terminal regulator, a 555 timer IC and a blinking LED and a  button switch..Throw in a few other components and you can test it out in a day or so..you can read one of the many 555 application notes here:
https://www.google.com/#hl=en&sugexp=les%3B&gs_nf=3&gs_mss=555%20timer%20one%20&tok=gwYytO3axQKzGgs16I2vbg&cp=33&gs_id=1r1&xhr=t&q=555+timer+one+shot+3+second+delay&pf=p&tbo=d&sclient=psy-ab&oq=555+timer+one+shot+3+second+delay&gs_l=&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&fp=f124fa16e2085d5e&bpcl=38897761&biw=1280&bih=826

Blinking LED's are also common..With no other circuity needed just power them on and they blink.I purchased a couple from futurlec..
However, if you are here to learn how to use Arduino like I am, then by all means ignore this and go the Arduino sketch method..
jolphil
Logged

Pages: [1]   Go Up
Jump to: