External Interruption isn't working

I wrote the code so when an interrupt occurs the LED’s counts from 0 to 15 binary one time and after that continue to blink.
I have set up my wiring correctly.
But, when I connect a jumper wire (in order to make an external interruption) to the digital pin 7 and touch a +Vcc of a LED for a moment, no interruption happen.
Am I wrong with the making interruption in a correct way?

int led11 = 11;
int led10 = 10;
int led9 = 9;
int led8 = 8;
int t=500;


void setup() { 
  Serial.begin(9600);          // start serial communication
  pinMode(led11, OUTPUT);     
  pinMode(led10, OUTPUT);    
  pinMode(led9, OUTPUT);    
  pinMode(led8, OUTPUT); 
  pinMode(6, INPUT);          

  attachInterrupt(7, testInterrupt, FALLING);
}

void loop(){
  digitalWrite(led11,HIGH);
  digitalWrite(led10,HIGH);
  digitalWrite(led9,HIGH);
  digitalWrite(led8,HIGH);

  delayMicroseconds(t);

  digitalWrite(led11,LOW);
  digitalWrite(led10,LOW);
  digitalWrite(led9,LOW);
  digitalWrite(led8,LOW);

  delayMicroseconds(t);
}

void testInterrupt(){
  //0000
  digitalWrite(led11, LOW);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //0001
  digitalWrite(led11, LOW);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t);
  //0010
  digitalWrite(led11, LOW);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, HIGH); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //0011
  digitalWrite(led11, LOW);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, HIGH); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t);
  //0100
  digitalWrite(led11, LOW);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //0101
  digitalWrite(led11, LOW);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t);
  //0110
  digitalWrite(led11, LOW);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9, HIGH); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //0111
  digitalWrite(led11, LOW);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9, HIGH); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t);
  //1000
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //1001
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t);
  //1010
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, HIGH); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //1011
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, LOW); 
  digitalWrite(led9, HIGH); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t);
  //1100
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //1101
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9, LOW); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t);
  //1110
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9,HIGH); 
  digitalWrite(led8, LOW); 
  delayMicroseconds(t);
  //1111
  digitalWrite(led11, HIGH);  
  digitalWrite(led10, HIGH); 
  digitalWrite(led9,HIGH); 
  digitalWrite(led8, HIGH); 
  delayMicroseconds(t); 

}

Please look at my attachment. All 3 are the same.

attachInterrupt(7, testInterrupt, FALLING);

On a Uno, there are two interrupts available, numbered 0 and 1.

They are triggered by Arduino digital pins 2 and 3 respectively. See here:

http://arduino.cc/en/Reference/attachInterrupt

So you need to change the 7 to 0 or 1, and then use the appropriate pin to trigger the interrupt.

EDIT: added ...

For your chosen pin (for example, 2), enable it as an input with internal pullup resistors:

pinMode(2, INPUT_PULLUP);

Then use the jumper to touch pin 2 to GND, to generate a falling edge.

You also should redesign your program and especially the interrupt service routine testInterrupt().

From the Arduino reference page I linked to ...

Inside the attached function, delay() won't work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. See the section on ISRs below for more information.

Also, read and act on the information on this page:

http://www.gammon.com.au/forum/?id=11488

Hackscribble: You also should redesign your program and especially the interrupt service routine testInterrupt().

Yes, this time I redesigned the program what may suitable with my arduino uno.

int led1 = 11;
int led2 = 10;
int led3 = 9;
int led4 = 8;


int counter = 0;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led1, OUTPUT);    
  pinMode(led2, OUTPUT);    
  pinMode(led3, OUTPUT); 
  pinMode(led4, OUTPUT); 
  attachInterrupt(0, activateCount,LOW);
}

// the loop routine runs over and over again forever:
void loop() {
 if (counter== 0){
   clear();
   counter = 1;
 } else if ( counter == 1){
   blink();
   counter = 0;
 }  else if( counter == 2){
   count15();
   counter = 0;
 }
}

void blink(){
  digitalWrite(led1, HIGH); 
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, HIGH);  
  delay(400); 
}

void clear(){
  digitalWrite(led1, LOW); 
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, LOW);  
  delay(400);    
}

void activateCount(){
  counter = 2;
}

void count15(){
  
  digitalWrite(led1, LOW); //0
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, LOW);  
  delay(1000);    
  digitalWrite(led1, LOW); //1
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, HIGH);  
  delay(1000);  
  digitalWrite(led1, LOW); //2
  digitalWrite(led2, LOW);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, LOW);  
  delay(1000);   
  digitalWrite(led1, LOW); //3
  digitalWrite(led2, LOW);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, HIGH);  
  delay(1000);   
  digitalWrite(led1, LOW); //4
  digitalWrite(led2, HIGH);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, LOW);  
  delay(1000);   
  digitalWrite(led1, LOW); //5
  digitalWrite(led2, HIGH);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, HIGH);  
  delay(1000);   
  digitalWrite(led1, LOW); //6
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, LOW);  
  delay(1000);   
  digitalWrite(led1, LOW); //7
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, HIGH);  
  delay(1000);
  digitalWrite(led1, HIGH); //8
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, LOW);  
  delay(1000);
  digitalWrite(led1, HIGH); //9
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, HIGH);  
  delay(1000);
  digitalWrite(led1, HIGH); //10
  digitalWrite(led2, LOW);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, LOW);  
  delay(1000);
  digitalWrite(led1, HIGH); //11
  digitalWrite(led2, LOW);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, HIGH);  
  delay(1000);
  digitalWrite(led1, HIGH); //12
  digitalWrite(led2, HIGH);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, LOW);  
  delay(1000);
  digitalWrite(led1, HIGH); //13
  digitalWrite(led2, HIGH);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, HIGH);  
  delay(1000);
  digitalWrite(led1, HIGH); //14
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, LOW);  
  delay(1000);
  digitalWrite(led1, HIGH); //15
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, HIGH);  
  counter = 0;
  delay(1000); 
}

But I don't get how to make the interruption. How should I wire the things in order to interrupt. In your previous post you have instructed a little bit.

Hackscribble: So you need to change the 7 to 0 or 1, and then use the appropriate pin to trigger the interrupt.

Then use the jumper to touch pin 2 to GND, to generate a falling edge.

Now I changed the pin 7 to 0. How to use the appropriate pin to trigger the interrupt?

How to use the appropriate pin to trigger the interrupt?

The interrupt is generated when the pin changes state. Apply or remove a voltage from the pin to trigger the interrupt, depending on whether you are using RISING, FALLING, or CHANGE as the interrupt trigger.

Activating the interrupt when the pin IS LOW doesn't make a lot of sense.

Now I get how interruption is. However how can I make interruption happen in my case? Please help.

You are using the jumper lead from pin 2 as a switch.

When it is not connected to anything else, the internal pull-up resistors make pin 2 high.

When you briefly touch the lead to GND, that takes pin 2 low.

You should declare counter as volatile.

volatile int counter = 0:

But I didn’t use the pin 2.

You have to use either pin 2 or pin 3. This is explained on the Arduino reference page linked earlier.

So I assume you used pin 3?

jabirfatah91:
But I didn’t use the pin 2.

you will also ned to DEBOUNCE that interrupt.

Look at this as your solution. it still has some of your blocking code, but works.

int led1 = 11;
int led2 = 10;
int led3 = 9;
int led4 = 8;
int led [] = {11, 10, 9, 8};


volatile int counter = 0;

// the setup routine runs once when you press reset:
void setup() 
{                
  // initialize the digital pin as an output.
  pinMode(led1, OUTPUT);    
  pinMode(led2, OUTPUT);    
  pinMode(led3, OUTPUT); 
  pinMode(led4, OUTPUT); 
  attachInterrupt(0, activateCount,LOW);
}

// the loop routine runs over and over again forever:
void loop() 
{
  if (counter== 0)
  {
    clear();
  } 
  else if ( counter == 1)
  {
    blink();
  }  
  else if( counter == 2)
  {
    count15();
  }
  else 
  { 
    counter = 0;
  }
}

void blink()
{
  digitalWrite(led1, HIGH); 
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);  
  digitalWrite(led4, HIGH);  
  delay(400);
  digitalWrite(led1, LOW); 
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, LOW);  
  delay(400);    
  
}

void clear(){
  digitalWrite(led1, LOW); 
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);  
  digitalWrite(led4, LOW);  
  delay(400);    
}

void activateCount()
{
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  if (interrupt_time - last_interrupt_time > 200)
  {
    counter++;
  }
  last_interrupt_time = interrupt_time;
}

void count15()
{
  for (byte i = 0; i <= 15; i++)
  {
    for (int j = 0; j < 4; j++)
    {
      digitalWrite(led[j], bitRead(i,j));
    }
    delay(1000);
  }
}

what is DEBOUNCH and how to make it worked? Iight now I am interrupting by I briefly touching the pin 2 with one of my LEDS leg (+Vcc). Only is it enough?

In your original code, you had set up attachInterrupt() to look for a FALLING edge, that is, when the input signal drops from +5V to 0V. That is why I suggested this in an earlier post ...

For your chosen pin (for example, 2), enable it as an input with internal pullup resistors:

pinMode(2, INPUT_PULLUP);

Then use the jumper to touch pin 2 to GND, to generate a falling edge.

"Bounce" is when you close a mechanical switch but the contacts very quickly open, then close, then open, then close, a few times before they settle down in the closed position. The Arduino works fast enough to detect [u]each[/u] of these open / close changes and generates multiple interrupts.

If a program is trying to count the number of times a switch is closed, these bounces would give extra counts, even though the user has only pressed the switch once.

Debouncing is about preventing incorrect readings like this, and it can be done in hardware or software.

In your program, you may not be affected by bounce because you call count15() when the ISR has set count to be 2, and count15() blocks until the counting is complete, at which point you reset count to 0. So another interrupt during count15() won't have an effect.

This project is solved, i want to thank you all.