Solved: Help with interrupts
hi everyone!
hardware setup: have series of leds connected breadboarded 328mpu (with arduino bootloader burned it), has simple push make switch (like this one) connected digital pin 3 ground. pull-up resistor pin 3 enabled.
aim: when powered on, chip causes leds flash in pretty pattern. want able push button, , have lights change pretty instantaneously flash in different pattern.
soooo... figured best use external interrupt achieve this. created code shown @ end of post.
the problem: interrupt seems work intermittently @ best. i'll press button , flash pattern change @ end of sequence (i.e. before loops round , starts again... carry on same pattern, though know interrupt fired (by including short code segment make 1 led flash when interrupt fires).
the code:
the references inreset attempts cause void_loop() restart after interrupt has fired, per information thread
is possible interrupt trigger to quick? interrupt run when interrupt conditions met? because, style of button logically assume unless 1 holds button down, produce falling, low , rising signals within short interval.
anyway, have no real idea problem is, or how solve it. or suggestions appreciated!
zerocool42
hardware setup: have series of leds connected breadboarded 328mpu (with arduino bootloader burned it), has simple push make switch (like this one) connected digital pin 3 ground. pull-up resistor pin 3 enabled.
aim: when powered on, chip causes leds flash in pretty pattern. want able push button, , have lights change pretty instantaneously flash in different pattern.
soooo... figured best use external interrupt achieve this. created code shown @ end of post.
the problem: interrupt seems work intermittently @ best. i'll press button , flash pattern change @ end of sequence (i.e. before loops round , starts again... carry on same pattern, though know interrupt fired (by including short code segment make 1 led flash when interrupt fires).
the code:
code: [select]
#include <avr/interrupt.h>
volatile int flashmode = 1;
int buttonpin = 3;
boolean inreset = false;
void setup() {
attachinterrupt(1, interrupt, low);
// set pins i'm using leds output
pinmode(buttonpin,input);
digitalwrite(buttonpin, high);
}
void loop() {
if (inreset) {
inreset = false;
}
if (flashmode == 3) {
flashmode = 1;
}
if (flashmode == 1) {
// start flash pattern 1. timing flashes managed using delay().
} else {
// flashmode must 2, start flash pattern 2. similar 1, timing of flashes managed using delay().
}
}
void interrupt()
{
flashmode++;
if (flashmode == 3) {
flashmode = 1;
}
inreset = true;
}
the references inreset attempts cause void_loop() restart after interrupt has fired, per information thread
is possible interrupt trigger to quick? interrupt run when interrupt conditions met? because, style of button logically assume unless 1 holds button down, produce falling, low , rising signals within short interval.
anyway, have no real idea problem is, or how solve it. or suggestions appreciated!
zerocool42
you need not use delay. there may silly hack have goto or modify delay function check button, modifying light sequence become state machine scaleable , best result.
Arduino Forum > Using Arduino > Programming Questions > Solved: Help with interrupts
arduino
Comments
Post a Comment