Interrupt funtion with delay()


i got arduino duemilanove last week , have been toying daily no major confusion until today.

i set 4 led's in digital 4-7, button on digital 3 , pot on analog 0.
the pot mapped 0-16 , number output in binary on leds.
the button should mini-knight rider effect, seems crash @ call of delay(100); , not until reset.

is there rule against using delay in interrupt call?
if so, why delaymicroseconds() work? (not me needs longer delay though)

code: [select]
int oldpot = 0;
int val;
int potval;
int k;

void setup(){
 ddrd = ddrd | b11110000;
 portd = portd ^ b11110000;
 attachinterrupt(1, krider, falling);
}

void loop(){
 potval = map(analogread(0), 0, 1023, 0, 15);
 if(oldpot != potval){
   portd = b11110000 & (~potval << 4);
   oldpot = potval;
   val = potval;
 }
}

void krider(){
 for(int = 0; < 4; i++){
   k = 1 << i;
   portd = b11110000 & (~k << 4);
   delay(100);
 }
 for(int = 3; >= 0; i--){
   k = 1 << i;
   portd = b11110000 & (~k << 4);
   delay(100);      
 }
}

any other tips , advice appreciated :)

you don't need k variable

for (i=1; i<=8; i=(i<<1))
 portd = b11110000 & i;

just out of curiosity, why use interrupt ?

could switch bounce part of problem.  you trigger interrupt, , while you're in delay, second high signal button re-triggers interrupt ?



Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Interrupt funtion with delay()


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums