Button to press at any time

Hey, I'm fairly new to Arduino and for my first project I'm making a laser tag gun, at the moment I'm laying the frame work. what I need help with is a button that can be pressed at any point in time, thanks.

const int LED = 13;
const int BUTTON = 7;
const int BULL = 2;
const int B2 = 3;
const int B3 = 4;
const int B4 = 5;
const int B5 = 6;
const int B6 = 9;
const int OUT = 8;
const int HIT = 10;
int bullets = 6;
int val = 0;  //set pins and variables
int hit = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() 

{ 
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);   //set pinmodes
  pinMode(BULL, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(B5, OUTPUT);
  pinMode(B6, OUTPUT);
  pinMode(OUT, OUTPUT);
  pinMode(HIT, INPUT);
}

void loop() 
{  
  val = digitalRead(BUTTON); //if the button is pressed the variable will become HIGH
  if (val == HIGH)
  {
    if(bullets == 0)
    {
      digitalWrite(OUT, HIGH);  //if there is no bullets you will not be able to shoot for three seconds
      delay(3000);
      digitalWrite(OUT, LOW);
      bullets = bullets + 6;
    }
    else
    {
      digitalWrite(LED, HIGH); //if the variable is HIGH the LED will turn on for 1/4 of a second and take away one bullet
      delay(250);
      digitalWrite(LED, LOW);
      bullets = bullets - 1;
      delay(1000);
    }
    if(bullets == 6)
    {  
      digitalWrite(BULL, HIGH); //if there is six bullets six lights will be on
      digitalWrite(B2, HIGH); 
      digitalWrite(B3, HIGH); 
      digitalWrite(B4, HIGH); 
      digitalWrite(B5, HIGH); 
      digitalWrite(B6, HIGH);
    }
    else

        if(bullets == 5)
      { 
        digitalWrite(BULL, LOW); //if there is five bullets five bullets will be on
        digitalWrite(B2, HIGH); 
        digitalWrite(B3, HIGH); 
        digitalWrite(B4, HIGH); 
        digitalWrite(B5, HIGH); 
        digitalWrite(B6, HIGH);
      }
      else

          if(bullets == 4)
        { 
          digitalWrite(BULL, LOW);  //if there is four bullets four lights will be on
          digitalWrite(B2, LOW); 
          digitalWrite(B3, HIGH); 
          digitalWrite(B4, HIGH); 
          digitalWrite(B5, HIGH); 
          digitalWrite(B6, HIGH);
        }
        else

            if(bullets == 3)
          { 
            digitalWrite(BULL, LOW); //if there is three bullets three lights will be on
            digitalWrite(B2, LOW); 
            digitalWrite(B3, LOW); 
            digitalWrite(B4, HIGH); 
            digitalWrite(B5, HIGH); 
            digitalWrite(B6, HIGH);
          } 
          else

              if(bullets == 2)
            { 
              digitalWrite(BULL, LOW); //if there is two bullets two lights will be on
              digitalWrite(B2, LOW); 
              digitalWrite(B3, LOW); 
              digitalWrite(B4, LOW); 
              digitalWrite(B5, HIGH); 
              digitalWrite(B6, HIGH);
            }
            else

                if(bullets == 1)
              { 
                digitalWrite(BULL, LOW); //if there is one bullet one light is on
                digitalWrite(B2, LOW); 
                digitalWrite(B3, LOW); 
                digitalWrite(B4, LOW); 
                digitalWrite(B5, LOW); 
                digitalWrite(B6, HIGH);
              } 
              else

                  if(bullets == 0)
                { 
                  digitalWrite(BULL, LOW);  //if there is no bullets all lights are off 
                  digitalWrite(B2, LOW); 
                  digitalWrite(B3, LOW); 
                  digitalWrite(B4, LOW); 
                  digitalWrite(B5, LOW); 
                  digitalWrite(B6, LOW);
                }       
unsigned long currentMillis =millis();
if(currentMillis - previousMillis >= interval); 
{
previousMillis = currentMillis;
hit = digitalRead(HIT); //if the button is pressed the variable will become HIGH
  if (hit == HIGH);
  {
    delay(10000);
  }
  }
}
}
[CODE]

[/code]

othersLASERtag.ino (2.96 KB)

Screen Shot 2015-09-22 at 9.03.24 am.png

Since you are new to using an Arduino, have you looked at the example sketches that were provided with your Arduino Software? One particular example is called BlinkWithoutDelay. It shows you how to get the same delay without actually using the delay() function.

Give it a look at and try to adapt your code to it. You might find your button responding a lot faster.

HazardsMind:
Since you are new to using an Arduino, have you looked at the example sketches that were provided with your Arduino Software? One particular example is called BlinkWithoutDelay. It shows you how to get the same delay without actually using the delay() function.

Give it a look at and try to adapt your code to it. You might find your button responding a lot faster.

OK, thanks I'm looking into it now

As far as your light animation goes, you can do something like this.

const byte Data = B00111111;
const byte Leds[6] = {2, 3, 4, 5, 6, 9};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  for (short i = 6; i >= 0; i--) // starts at 6 unfired bullets and goes down to 0 remaining
  {
    Serial.println( int(Data & (~Data >> i)), BIN);
    BulletsFired(i);
  }
}

void BulletsFired(const byte B)
{
  // no negative index. 
  if (B > 0) 
    digitalWrite(Leds[B - 1], (Data & (~Data >> B)) );
  else 
  {
    digitalWrite(Leds[0], LOW);
    Serial.println("All Off");
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}

Result:

111111
111110
111100
111000
110000
100000
0

HazardsMind:
Since you are new to using an Arduino, have you looked at the example sketches that were provided with your Arduino Software? One particular example is called BlinkWithoutDelay. It shows you how to get the same delay without actually using the delay() function.

Give it a look at and try to adapt your code to it. You might find your button responding a lot faster.

Ok, I looked into millis, I've got it working mostly, however its being triggered when I touch BUTTON as well as when I touch HIT

const int LED = 13;
const int BUTTON = 7;
const int BULL = 2;
const int B2 = 3;
const int B3 = 4;
const int B4 = 5;
const int B5 = 6;
const int B6 = 9;
const int OUT = 8;
const int HIT = 10;
int bullets = 6;
int val = 0;  //set pins and variables
int hit = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() 

{ 
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);   //set pinmodes
  pinMode(BULL, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(B5, OUTPUT);
  pinMode(B6, OUTPUT);
  pinMode(OUT, OUTPUT);
  pinMode(HIT, INPUT);
}

void loop() 
{  
  val = digitalRead(BUTTON); //if the button is pressed the variable will become HIGH
  if (val == HIGH)
  {
    if(bullets == 0)
    {
      digitalWrite(OUT, HIGH);  //if there is no bullets you will not be able to shoot for three seconds
      delay(3000);
      digitalWrite(OUT, LOW);
      bullets = bullets + 6;
    }
    else
    {
      digitalWrite(LED, HIGH); //if the variable is HIGH the LED will turn on for 1/4 of a second and take away one bullet
      delay(250);
      digitalWrite(LED, LOW);
      bullets = bullets - 1;
      delay(1000);
    }
    if(bullets == 6)
    {  
      digitalWrite(BULL, HIGH); //if there is six bullets six lights will be on
      digitalWrite(B2, HIGH); 
      digitalWrite(B3, HIGH); 
      digitalWrite(B4, HIGH); 
      digitalWrite(B5, HIGH); 
      digitalWrite(B6, HIGH);
    }
    else

        if(bullets == 5)
      { 
        digitalWrite(BULL, LOW); //if there is five bullets five bullets will be on
        digitalWrite(B2, HIGH); 
        digitalWrite(B3, HIGH); 
        digitalWrite(B4, HIGH); 
        digitalWrite(B5, HIGH); 
        digitalWrite(B6, HIGH);
      }
      else

          if(bullets == 4)
        { 
          digitalWrite(BULL, LOW);  //if there is four bullets four lights will be on
          digitalWrite(B2, LOW); 
          digitalWrite(B3, HIGH); 
          digitalWrite(B4, HIGH); 
          digitalWrite(B5, HIGH); 
          digitalWrite(B6, HIGH);
        }
        else

            if(bullets == 3)
          { 
            digitalWrite(BULL, LOW); //if there is three bullets three lights will be on
            digitalWrite(B2, LOW); 
            digitalWrite(B3, LOW); 
            digitalWrite(B4, HIGH); 
            digitalWrite(B5, HIGH); 
            digitalWrite(B6, HIGH);
          } 
          else

              if(bullets == 2)
            { 
              digitalWrite(BULL, LOW); //if there is two bullets two lights will be on
              digitalWrite(B2, LOW); 
              digitalWrite(B3, LOW); 
              digitalWrite(B4, LOW); 
              digitalWrite(B5, HIGH); 
              digitalWrite(B6, HIGH);
            }
            else

                if(bullets == 1)
              { 
                digitalWrite(BULL, LOW); //if there is one bullet one light is on
                digitalWrite(B2, LOW); 
                digitalWrite(B3, LOW); 
                digitalWrite(B4, LOW); 
                digitalWrite(B5, LOW); 
                digitalWrite(B6, HIGH);
              } 
              else

                  if(bullets == 0)
                { 
                  digitalWrite(BULL, LOW);  //if there is no bullets all lights are off 
                  digitalWrite(B2, LOW); 
                  digitalWrite(B3, LOW); 
                  digitalWrite(B4, LOW); 
                  digitalWrite(B5, LOW); 
                  digitalWrite(B6, LOW);
                }       
unsigned long currentMillis =millis();
if(currentMillis - previousMillis >= interval); 
{
previousMillis = currentMillis;
hit = digitalRead(HIT); //if the button is pressed the variable will become HIGH
  if (hit == HIGH);
  {
    delay(10000);
  }
  }
}
}
[CODE]

So, I've made a base for a laser tag system, In order to finish the program I need to implement IR and fix my 'out' system. My problem is that every time I shoot it puts me out, when I want it to only go out when the out button is hit. I can't understand why my program isn't work.

const int LED = 13;
const int BUTTON = 7;
const int BULL = 2;
const int B2 = 3;
const int B3 = 4;
const int B4 = 5;
const int B5 = 6;
const int B6 = 9;
const int OUT = 8;
const int HIT = 10;
int bullets = 6;
int val = 0;  //set pins and variables
int hit = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() 

{ 
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);   //set pinmodes
  pinMode(BULL, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(B5, OUTPUT);
  pinMode(B6, OUTPUT);
  pinMode(OUT, OUTPUT);
  pinMode(HIT, INPUT);
}

void loop() 
{  
  val = digitalRead(BUTTON); //if the button is pressed the variable will become HIGH
  if (val == HIGH)
  {
    if(bullets == 0)
    {
      digitalWrite(OUT, HIGH);  //if there is no bullets you will not be able to shoot for three seconds
      delay(3000);
      digitalWrite(OUT, LOW);
      bullets = bullets + 6;
    }
    else
    {
      digitalWrite(LED, HIGH); //if the variable is HIGH the LED will turn on for 1/4 of a second and take away one bullet
      delay(250);
      digitalWrite(LED, LOW);
      bullets = bullets - 1;
      delay(1000);
    }
    if(bullets == 6)
    {  
      digitalWrite(BULL, HIGH); //if there is six bullets six lights will be on
      digitalWrite(B2, HIGH); 
      digitalWrite(B3, HIGH); 
      digitalWrite(B4, HIGH); 
      digitalWrite(B5, HIGH); 
      digitalWrite(B6, HIGH);
    }
    else

        if(bullets == 5)
      { 
        digitalWrite(BULL, LOW); //if there is five bullets five bullets will be on
        digitalWrite(B2, HIGH); 
        digitalWrite(B3, HIGH); 
        digitalWrite(B4, HIGH); 
        digitalWrite(B5, HIGH); 
        digitalWrite(B6, HIGH);
      }
      else

          if(bullets == 4)
        { 
          digitalWrite(BULL, LOW);  //if there is four bullets four lights will be on
          digitalWrite(B2, LOW); 
          digitalWrite(B3, HIGH); 
          digitalWrite(B4, HIGH); 
          digitalWrite(B5, HIGH); 
          digitalWrite(B6, HIGH);
        }
        else

            if(bullets == 3)
          { 
            digitalWrite(BULL, LOW); //if there is three bullets three lights will be on
            digitalWrite(B2, LOW); 
            digitalWrite(B3, LOW); 
            digitalWrite(B4, HIGH); 
            digitalWrite(B5, HIGH); 
            digitalWrite(B6, HIGH);
          } 
          else

              if(bullets == 2)
            { 
              digitalWrite(BULL, LOW); //if there is two bullets two lights will be on
              digitalWrite(B2, LOW); 
              digitalWrite(B3, LOW); 
              digitalWrite(B4, LOW); 
              digitalWrite(B5, HIGH); 
              digitalWrite(B6, HIGH);
            }
            else

                if(bullets == 1)
              { 
                digitalWrite(BULL, LOW); //if there is one bullet one light is on
                digitalWrite(B2, LOW); 
                digitalWrite(B3, LOW); 
                digitalWrite(B4, LOW); 
                digitalWrite(B5, LOW); 
                digitalWrite(B6, HIGH);
              } 
              else

                  if(bullets == 0)
                { 
                  digitalWrite(BULL, LOW);  //if there is no bullets all lights are off 
                  digitalWrite(B2, LOW); 
                  digitalWrite(B3, LOW); 
                  digitalWrite(B4, LOW); 
                  digitalWrite(B5, LOW); 
                  digitalWrite(B6, LOW);
                }       
unsigned long currentMillis =millis();
if(currentMillis - previousMillis >= interval); 
{
previousMillis = currentMillis;
hit = digitalRead(HIT); //if the button is pressed the variable will become HIGH
  if (hit == HIGH);
  {
    delay(10000);
  }
  }
}
}
[CODE]
Thanks in advance

Hi,
Is your OUT button using a pullup or pull down resistor?
Any input has to be HIGH or LOW, if you have a button pulling the input HIGH, you need a 10K resistor to pull the input LOW when you release the button.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you powering the controller and what controller model are you using?

Tom... :slight_smile:

TomGeorge:
Hi,
Is your OUT button using a pullup or pull down resistor?
Any input has to be HIGH or LOW, if you have a button pulling the input HIGH, you need a 10K resistor to pull the input LOW when you release the button.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How are you powering the controller and what controller model are you using?

Tom... :slight_smile:

OUT is not a button, it is an LED, however I have attached my circuit to the original post and I am using freetronics eleven, it is an Arduino Uno compatible board and it's basically a knockoff version

my tv IR bounces off walls and works great if I point it away from the TV.

are you shooting yourself ?

dave-in-nj:
my tv IR bounces off walls and works great if I point it away from the TV.

are you shooting yourself ?

I'm actually going to be making two

Hi,

OUT is not a button, it is an LED, however I have attached my circuit to the original post and I am using freetronics eleven, it is an Arduino Uno compatible board and it's basically a knockoff version

Please do not go and edit old posts, it disjoints the flow of the thread.
Anyone later looking at this thread for answers to their problems, will find that some answers do not make sense because they refer to remarks made earlier that have since been changed.

I want it to only go out when the out button is hit.

That "out" button is what I was referring to.

Tom.... :slight_smile:

TomGeorge:
Hi,

Please do not go and edit old posts, it disjoints the flow of the thread.
Anyone later looking at this thread for answers to their problems, will find that some answers do not make sense because they refer to remarks made earlier that have since been changed.
That "out" button is what I was referring to.

Tom.... :slight_smile:

I edited the first post as I do not know how to attach pictures to new posts on a topic. I don't completely understand pull-up resistors vs pull-down however as far as I understand mine is using pull-up

Hi,

When you shoot is an LED supposed to light, one per shot?

Do you have resistors in series with those LEDs to limit the current through them?
If not then the current surge through them could be resetting your UNO.
They are not shown on your fritzy diagram and they are essential to prevent damaging your UNO.

Tom.... :slight_smile:

TomGeorge:
Hi,

When you shoot is an LED supposed to light, one per shot?

Do you have resistors in series with those LEDs to limit the current through them?
If not then the current surge through them could be resetting your UNO.
They are not shown on your fritzy diagram and they are essential to prevent damaging your UNO.

Tom.... :slight_smile:

Yes, every shot lights up an LED at the moment, the LED's have no resistors attached, I will attempt to attach them, however I'm quite skeptical as when I press the first button, it completes the action of another. When this resetting happens does it generally pause? Also, what ohm resistor do you recommend?

Hi,
Resistor value between 220 Ohms up to 680 Ohms on each LED.
Do you know why they are needed?

https://www.sparkfun.com/tutorials/219

Tom.... :slight_smile:
Do not try it again until you have fitted the resisitors

TomGeorge:
Hi,
Resistor value between 220 Ohms up to 680 Ohms on each LED.
Do you know why they are needed?

LED Current Limiting Resistors - SparkFun Electronics

Tom.... :slight_smile:
Do not try it again until you have fitted the resisitors

Yes, I understand the basics, however, I do not understand how you decide what resistors you need, I quickly fitted 1k resistors before you responded, all the LEDs work however the problem is still present. I am changing to 680 right now

Hi,
1K is fine, just depends on how bright you want your LEDs.
Tom... :slight_smile:

TomGeorge:
Hi,
1K is fine, just depends on how bright you want your LEDs.
Tom... :slight_smile:

So, do you have any other recommendations?

I checked the lates code I could found in the post and that gave me

FLasertagOrg.ino: In function 'void loop()':
FLasertagOrg.ino:128:47: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
FLasertagOrg.ino:132:19: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]

after changing that and simplifying the led display stuff, here you get something to test

const int LED = 13;
const int BUTTON = 7;
const int BULL = 2;
const int B2 = 3;
const int B3 = 4;
const int B4 = 5;
const int B5 = 6;
const int B6 = 9;
const int OUT = 8;
const int HIT = 10;
int bullets = 6;
int val = 0;  //set pins and variables
int hit = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup()

{
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);   //set pinmodes
  pinMode(BULL, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(B5, OUTPUT);
  pinMode(B6, OUTPUT);
  pinMode(OUT, OUTPUT);
  pinMode(HIT, INPUT);
}

void loop()
{
  val = digitalRead(BUTTON); //if the button is pressed the variable will become HIGH
  if (val == HIGH)
  {
    if (bullets == 0)
    {
      digitalWrite(OUT, HIGH);  //if there is no bullets you will not be able to shoot for three seconds
      delay(3000);
      digitalWrite(OUT, LOW);
      bullets = bullets + 6;
    }
    else
    {
      digitalWrite(LED, HIGH); //if the variable is HIGH the LED will turn on for 1/4 of a second and take away one bullet
      delay(250);
      digitalWrite(LED, LOW);
      bullets = bullets - 1;
      delay(1000);
    }
    switch (bullets) {
      case 0: digitalWrite(B6, LOW);
      case 1: digitalWrite(B5, LOW);
      case 2: digitalWrite(B4, LOW);
      case 3: digitalWrite(B3, LOW);
      case 4: digitalWrite(B2, LOW);
      case 5: digitalWrite(BULL, LOW);
      case 6:
        break;
      default:
        Serial.println("unhandled case in LOW");
    }
    switch (bullets) {
      case 6: digitalWrite(BULL, HIGH);
      case 5: digitalWrite(B2, HIGH);
      case 4: digitalWrite(B3, HIGH);
      case 3: digitalWrite(B4, HIGH);
      case 2: digitalWrite(B5, HIGH);
      case 1: digitalWrite(B6, HIGH);
      case 0:
        break;
      default:
        Serial.println("unhandled case in HIGH");
    }
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval)
    {
      previousMillis = currentMillis;
      hit = digitalRead(HIT); //if the button is pressed the variable will become HIGH
      if (hit == HIGH)
      {
        delay(10000);
      }
    }
  }
}

There are major problems left

  1. your button logic does not check for the unpressed/pressed change, but "autofires".
    (this will become obvious when you get rid of the dreadful delays)

  2. your delays are unsuitable to achieve the desired result
    (you cant be hit while delaying...very realistic)

Whandall:
I checked the lates code I could found in the post and that gave me

FLasertagOrg.ino: In function 'void loop()':

FLasertagOrg.ino:128:47: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
FLasertagOrg.ino:132:19: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]



after changing that and simplifying the led display stuff, here you get something to test



const int LED = 13;
const int BUTTON = 7;
const int BULL = 2;
const int B2 = 3;
const int B3 = 4;
const int B4 = 5;
const int B5 = 6;
const int B6 = 9;
const int OUT = 8;
const int HIT = 10;
int bullets = 6;
int val = 0;  //set pins and variables
int hit = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup()

{
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);  //set pinmodes
  pinMode(BULL, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(B5, OUTPUT);
  pinMode(B6, OUTPUT);
  pinMode(OUT, OUTPUT);
  pinMode(HIT, INPUT);
}

void loop()
{
  val = digitalRead(BUTTON); //if the button is pressed the variable will become HIGH
  if (val == HIGH)
  {
    if (bullets == 0)
    {
      digitalWrite(OUT, HIGH);  //if there is no bullets you will not be able to shoot for three seconds
      delay(3000);
      digitalWrite(OUT, LOW);
      bullets = bullets + 6;
    }
    else
    {
      digitalWrite(LED, HIGH); //if the variable is HIGH the LED will turn on for 1/4 of a second and take away one bullet
      delay(250);
      digitalWrite(LED, LOW);
      bullets = bullets - 1;
      delay(1000);
    }
    switch (bullets) {
      case 0: digitalWrite(B6, LOW);
      case 1: digitalWrite(B5, LOW);
      case 2: digitalWrite(B4, LOW);
      case 3: digitalWrite(B3, LOW);
      case 4: digitalWrite(B2, LOW);
      case 5: digitalWrite(BULL, LOW);
      case 6:
        break;
      default:
        Serial.println("unhandled case in LOW");
    }
    switch (bullets) {
      case 6: digitalWrite(BULL, HIGH);
      case 5: digitalWrite(B2, HIGH);
      case 4: digitalWrite(B3, HIGH);
      case 3: digitalWrite(B4, HIGH);
      case 2: digitalWrite(B5, HIGH);
      case 1: digitalWrite(B6, HIGH);
      case 0:
        break;
      default:
        Serial.println("unhandled case in HIGH");
    }
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval)
    {
      previousMillis = currentMillis;
      hit = digitalRead(HIT); //if the button is pressed the variable will become HIGH
      if (hit == HIGH)
      {
        delay(10000);
      }
    }
  }
}



There are major problems left

1. your button logic does not check for the unpressed/pressed change, but "autofires".
(this will become obvious when you get rid of the dreadful delays) 

2. your delays are unsuitable to achieve the desired result
(you cant be hit while delaying...very realistic)

How do I get rid of delays? Is there a tutorial you would recommend?