Go Down

Topic: Problem with interrupts (Read 569 times) previous topic - next topic

pt_t

Jan 04, 2013, 03:34 am Last Edit: Jan 04, 2013, 04:23 am by Coding Badly Reason: 1
hi i'm new with arduino and i have a problem with interrupts, i was testing this code:

Code: [Select]
int pin = 10;
volatile int state = LOW;

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void blink()
{
  state = !state;
}


but im not sure about why the led change when i connect to ground, if i conect to 5 volts nothing happens, i have an arduinomega

thanks


Moderator edit: [code] [/code] tags added.

MarkT

1) code tags please!

2) connect _what_ to 5V or ground?  where is the LED?
[ I won't respond to messages, use the forum please ]

pt_t

sorry for the code tags,  and i  connected  the interrupt pin (pin2) to 5v, this is like a sensor signal i think ,so why does not activate the interrupt ???
and the led is on pin10

thanks

JimboZA

Do you know if the LED actually works? It starts off LOW.... if it's faulty then it might be trying to go on when you apply the interrupt but you can't see it.

Maybe change the line volatile int state = LOW; to volatile int state = HIGH; so it starts in the "on" state and you'll be confident it actually works.
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

pt_t

thank you jimboza, I tried your idea, but the LED works well, and something strange happens when I connect pin2 to ground, changes state   :S

Nick Gammon

If you move pin 2 from Gnd to +5V (and back) does the LED toggle?
http://www.gammon.com.au/electronics

JimboZA


...and something strange happens ...


And what is that strange thing?
Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

pt_t

if I connect the ground to pin2    the state of LED changes  or just connect a wire to pin2( i dont know why) , but if a connect 5 volts and back nothings append .....

and now I'm testing on  RISING mode

is it clear? maybe my English is another problem xD

Nick Gammon

The pin needs a defined state. Just connecting and disconnecting a wire is not that. Enable the internal pull-ups, or use an external resistor.
http://www.gammon.com.au/electronics

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview