interrupt controls LEDs

Hi,
I have to read out pulses from 9 flow sensors. Each pulse width is about 20 ms long.
I detect the pulses via interrupt, because I am using the Arduino Due.
"...The Arduino Due board has powerful interrupt capabilities that allows you to attach an interrupt function on all available pins. You can directly specify the pin number in attachInterrupt().."
Each time each status changes I want to call each underfunction to change the LED from on to off or otherwise.
I tried with faster baudrate, now I reduced it again.
I tried with RISING and FALLING
I had array declarations for pins and status which I changed to a one by one declaration.
I testet my setup and it just works for 3 pins (not always the same) that`s the reason why I think that my programm is not correct.

So, here it is: (I hope you can help me out)

volatile int state1 = LOW;
volatile int state2 = LOW;
volatile int state3 = LOW;
volatile int state4 = LOW;
volatile int state5 = LOW;
volatile int state6 = LOW;
volatile int state7 = LOW;
volatile int state8 = LOW;
volatile int state9 = LOW;

void setup()
{
Serial.begin(9600);

pinMode(20, INPUT);
pinMode(21, INPUT);
pinMode(24, INPUT);
pinMode(25, INPUT);
pinMode(28, INPUT);
pinMode(29, INPUT);
pinMode(32, INPUT);
pinMode(33, INPUT);
pinMode(36, INPUT);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(11, OUTPUT);

digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(11, LOW);

attachInterrupt(20, LED1, CHANGE);
attachInterrupt(21, LED2, CHANGE);
attachInterrupt(24, LED3, CHANGE);
attachInterrupt(25, LED4, CHANGE);
attachInterrupt(28, LED5, CHANGE);
attachInterrupt(29, LED6, CHANGE);
attachInterrupt(32, LED7, CHANGE);
attachInterrupt(33, LED8, CHANGE);
attachInterrupt(36, LED9, CHANGE);

}

void loop()
{
delay(10);
digitalWrite(2, state1);
digitalWrite(3, state2);
digitalWrite(4, state3);
digitalWrite(5, state4);
digitalWrite(6, state5);
digitalWrite(7, state6);
digitalWrite(8, state7);
digitalWrite(9, state8);
digitalWrite(11, state9);
}

void LED1()
{
state1 = !state1;
}
void LED2()
{
state2 = !state2;
}
void LED3()
{
state3 = !state3;
}
void LED4()
{
state4 = !state4;
}
void LED5()
{
state5 = !state5;
}
void LED6()
{
state6 = !state6;
}
void LED7()
{
state7 = !state7;
}
void LED8()
{
state8 = !state8;
}
void LED9()
{
state9 = !state9;
}

volatile int state1 = LOW;
volatile int state2 = LOW;
volatile int state3 = LOW;
volatile int state4 = LOW;
volatile int state5 = LOW;
volatile int state6 = LOW;
volatile int state7 = LOW;
volatile int state8 = LOW;
volatile int state9 = LOW;

Have you ever heard of arrays?

  delay(10);

Why?

Why is loop() doing anything? Write the new state to the pin in the ISR.

I tried with faster baudrate, now I reduced it again.

You are not Serial.print()ing anything. Therefore, baud rate has nothing to do with your issue.

I had array declarations for pins and status which I changed to a one by one declaration.

Put them back.

I testet my setup and it just works for 3 pins (not always the same) that`s the reason why I think that my programm is not correct.

It's likely, if it works for three, that it is a wiring issue or a issue with the sensors, not a programming issue.

If the flow sensors are sending data too fast for the Arduino to keep up, interrupts will be lost.

Welcome to the Forum. Please read Nick Gammon's two posts at the top of this Forum on guidelines for posting here, especially the use of code tags ("</>") when posting source code. It will help us help you.

Actually, if the pulses last 20ms. you don't need interrupts at all.

ok, I will do that next time I post a source code, sorry for that.

Actually I checked every wire and they are all conected as they should be.

aarg:
Actually, if the pulses last 20ms. you don't need interrupts at all.

I do not understand what you mean. Can you explain that to me?

Can you blink once every 10 milliseconds? If not, perhaps the LED's aren't on long enough to see them.

Yes, the LED´s can blink that fast (just tested it)

You program is conceptually sound, you got the frame.

Now you should work on details and worry about crossing the t's and dotting the i's later - AKA loops and arrays.

  1. Is you sensor idle state at ground or "open collector" output? In other words - is the 20 ms pulse low-high to high-low? Setting pinMode to INPUT_PULLUP may be safer.

  2. Selecting CHANGE on attchaInterrup implies TWO actions on your pulse, irregardless of actual pulse shape.
    Trigger corresponding interrupt on leading edge of the pulse and trigger it again on trailing edge.

  3. Assuming you keep CHANGE ( see above) do you want the LED to turn on / off DURING the pulse?
    Or you want to turn it on and than off on NEXT pulse? Or perhaps turn the LED on for a selected time?

  4. Keep all the "action" - LED on / off in ISR.

  5. Global variables are fine in simple application, but I prefer to keep variables closer to where they are used.
    For example LED state could be declared in the corresponding ISR.

PS I am trying to figure out how to emulate interrupt inputs, so far it looks as brute force is the "solution" - physically connecting output pin to input pin.

rab1:
I do not understand what you mean. Can you explain that to me?

In 20 ms. you have more than sufficient time to poll all the input pins (in other words, just read them). You can do that in the loop() function. You don't need interrupts.