Weird behavior of external interrupts
for project, i'm using 2 internal pull-up resistor buttons on arduino uno.
both work in conjunction interrupt in order trigger specific function outside of loop().
for reason, when exiting 1 of functions, programmingmode() or cleaningmode(), program seems
trigger function again if hold down button long. if press , release either button quickly,
the program functions normally.
i have 2 theories, although attempts solve either 1 have not solved problem:
1. when either button pressed within programmingmode() or cleaningmode(), interrupt called second time.
2. the interrupts, although set falling, somehow pickup rising action of button well??
here's code:
moderator edit: [code] [/code] tags added.
both work in conjunction interrupt in order trigger specific function outside of loop().
for reason, when exiting 1 of functions, programmingmode() or cleaningmode(), program seems
trigger function again if hold down button long. if press , release either button quickly,
the program functions normally.
i have 2 theories, although attempts solve either 1 have not solved problem:
1. when either button pressed within programmingmode() or cleaningmode(), interrupt called second time.
2. the interrupts, although set falling, somehow pickup rising action of button well??
here's code:
code: [select]
int programmingpin = 2;
int cleaningpin = 3;
int interruptprogramming = 0;
int interruptcleaning = 1;
volatile int programmingstatus = 0;
volatile int cleaningstatus = 0;
void setup()
{
attachinterrupt(interruptprogramming, isprogrammingmode, falling);
attachinterrupt(interruptcleaning, iscleaningmode, falling);
digitalwrite(programmingpin, high);
digitalwrite(cleaningpin, high);
}
void loop()
{
if (programmingstatus == 1)
{
programmingmode();
programmingstatus = 0;
}
if (cleaningstatus == 1)
{
cleaningmode();
cleaningstatus = 0;
}
}
void isprogrammingmode()
{
programmingstatus = 1;
}
void iscleaningmode()
{
cleaningstatus = 1;
}
void programmingmode()
{
for ( ; ; )
{
if (digitalread(programmingpin) == low)
{
break;
}
}
}
void cleaningmode()
{
for ( ; ; )
{
if (digitalread(cleaningpin) == low)
{
break;
}
}
}
moderator edit: [code] [/code] tags added.
a couple of questions me understand doing
1. mean "i'm using 2 internal pull-up resistor buttons" ?
2. empty loops in functions ?
1. mean "i'm using 2 internal pull-up resistor buttons" ?
2. empty loops in functions ?
Arduino Forum > Using Arduino > Programming Questions > Weird behavior of external interrupts
arduino
Comments
Post a Comment