why arduino spits lots of data after an interrupt?
hi,
why might arduino spit out lots of data (more should given delay) directly after interrupt called?
here's code interested:
#define bounce_duration 2000 // define appropriate bounce time in ms switches
volatile unsigned long bouncetime=0; // variable hold ms count debounce pressed switch
int read_val = 0;
int b = 0;
int trig = 0; //flag control header printed before reads
char changer;
void setup ()
{
serial.begin (115200);
attachinterrupt(1, trigger, change);
}
void loop () {
if (trig == 1)
{
serial.print("read");
for (b=0; b<4; b++)
{
read_val = analogread(b);
serial.print(read_val,dec);
}
changer = 'f';
delay(500);
}
if (trig == 0)
{
serial.print("dare");
for (b=0; b<4; b++)
{
read_val = analogread(b);
serial.print(read_val,dec);
}
changer = 'o';
delay(500);
}
}
void trigger ()
{
if(millis() > bouncetime)
{
if (changer == 'o')
{
trig = 1;
}
if (changer == 'f')
{
trig = 0;
}
bouncetime = millis() + bounce_duration;
}
}
why might arduino spit out lots of data (more should given delay) directly after interrupt called?
here's code interested:
#define bounce_duration 2000 // define appropriate bounce time in ms switches
volatile unsigned long bouncetime=0; // variable hold ms count debounce pressed switch
int read_val = 0;
int b = 0;
int trig = 0; //flag control header printed before reads
char changer;
void setup ()
{
serial.begin (115200);
attachinterrupt(1, trigger, change);
}
void loop () {
if (trig == 1)
{
serial.print("read");
for (b=0; b<4; b++)
{
read_val = analogread(b);
serial.print(read_val,dec);
}
changer = 'f';
delay(500);
}
if (trig == 0)
{
serial.print("dare");
for (b=0; b<4; b++)
{
read_val = analogread(b);
serial.print(read_val,dec);
}
changer = 'o';
delay(500);
}
}
void trigger ()
{
if(millis() > bouncetime)
{
if (changer == 'o')
{
trig = 1;
}
if (changer == 'f')
{
trig = 0;
}
bouncetime = millis() + bounce_duration;
}
}
i have guess, that's is.
while arduino handling interrupt, things can go on in background (not instructions, hardware stuff). when isr returns, data gets flushed out of buffers. the serial port has (small) buffer. maybe that's it.
while arduino handling interrupt, things can go on in background (not instructions, hardware stuff). when isr returns, data gets flushed out of buffers. the serial port has (small) buffer. maybe that's it.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > why arduino spits lots of data after an interrupt?
arduino
Comments
Post a Comment