Interrupt questions


i'm trying out interrupts first time. i've read them . want use them run program displays information on glcd while using delay function. want interrupt activate on button press perform function , go beginning of void loop(). know interrupts stop delay function fro working 'm using delaymicroseconds function.  problem code below program doesn't respond every button push , when respond led 13 switches state immediately. hardware debouncing switch.

main questions
1: have why led 13 switching sometimes.
2: why not respond @ sometimes
3: how go beginning of void loop interrupt function.

code: [select]
int pin = 13;
volatile int state = low;

void setup()
{
  pinmode(pin, output);
  attachinterrupt(0, blink, rising);
}

void loop()
{
  digitalwrite(pin, state);
  delaymicroseconds(10000);
}

void blink()
{
  state = !state;
}

an interrupt interferes timing while interrupt active. interrupt routine commendably short won't have effect on timing.

if press button while delaymicroseconds() working interrupt trigger code go straight , complete delaymicroseconds() fact button pressed won't noticed.

if purpose of code switch led on , off rid of delay altogether , see happens.

i assume code learn interrupts. not necessary this.

...r


Arduino Forum > Using Arduino > Programming Questions > Interrupt questions


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support