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;
}