Go Down

Topic: [Arduino uno R3] INT0 triggered by digital pin 3 (Read 818 times) previous topic - next topic

sprzedamsanki

I've made simple circuit to master Arduino interrupts. I wrote also a simple program keeping track of how many times button has been pressed. For unknown reasons Arduino seems to call INT0 interrupt even on change on digital pin 3. What am I doing wrong?

Here's code, and circuit:
Code: [Select]
volatile int count0 = 0;

void setup()
{
  Serial.begin(9600);
 
  // Set input and pullups
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);
 
  // Set INT0 interrupt:
  attachInterrupt(0, interrupt0, FALLING);
}

void loop()
{
  Serial.println(count0);
  Serial.println(count1);
  delay(1000);
}

void interrupt0()
{
  Serial.println("Interrupt0");
  count0++;
}




Uploaded with ImageShack.us
'The most exciting phrase to hear in science, the only one that heralds new discoveries, is not "Eureka!", but rather, "Hmm... that's funny.

ematson5897

This doesn't help you but just btw this
Code: [Select]
pinMode(2, INPUT);
  digitalWrite(2, HIGH);


can be changed to this

Code: [Select]
pinMode(2,INPUT_PULLUP);

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy