void digitalWrite(int pin, int val){ if (digitalPinToPort(pin) != NOT_A_PIN) { // If the pin that support PWM output, we need to turn it off // before doing a digital write.

if (analogOutPinToBit(pin) == 1) timer1PWMAOff();

if (analogOutPinToBit(pin) == 2) timer1PWMBOff();

if (analogOutPinToBit(pin) == 3) timer2PWMOff();

if (val == LOW) cbi(_SFR_IO8(port_to_output[digitalPinToPort(pin)]), digitalPinToBit(pin)); else sbi(_SFR_IO8(port_to_output[digitalPinToPort(pin)]), digitalPinToBit(pin)); }}So you cannot use an array in place of int type definition of the pin parameter of the digitalWrite function.

But I think you can make your own definition of a new function wich can use an int array as parameter.

Thanks for digging that out, I'll give it a shot sometime this week. However....

Only just had time to sit down and start figuring out how I might do this (before reading your message).I have been doubling up some code that worked with one sensor, the data I am getting back seems to be the combined value of the two sensors wired to digital pins 6 and 7, which I am guessing is something to do with this bit:

But I have a question: do you have to read the two sensors simultaneously? Some 10's milliseconds between the read of the two sensors could be acceptable for your project?

At the first read,- I think that an array doesn't change anything ;- your code could have some problems if B sensor take a pulse before the A sensor ;- using external interrupt could be a best solution for you ;- you can reduce your code and optimize it by replacing :int aultraSoundSignal = 6; // US 1int bultraSoundSignal = 7; // US 2by#define aultraSoundSignal 6#define bultraSoundSignal 7note that there no ; at the end of the line.

Hi Benoît,A delay of that length will be no problem at all. I had thought that looping the routine and alternating the active pins might be a way around the problem but it was a little late to start working on that last night.I'll try a few things out this evening.

/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH * or LOW, the type of pulse to measure. Works on pulses from 10 microseconds * to 3 minutes in length, but must be called at least N microseconds before * the start of the pulse. */unsigned long pulseIn(int pin, int state){ // cache the port and bit of the pin in order to speed up the // pulse width measuring loop and achieve finer resolution. calling // digitalWrite() instead yields much coarser resolution. int r = port_to_input[digitalPinToPort(pin)]; int bit = digitalPinToBit(pin); int mask = 1 << bit; unsigned long width = 0;

// compute the desired bit pattern for the port reading (e.g. set or // clear the bit corresponding to the pin being read). the !!state // ensures that the function treats any non-zero value of state as HIGH. state = (!!state) << bit;

// convert the reading to microseconds. the slower the CPU speed, the // proportionally fewer iterations of the loop will occur (e.g. a // 4 MHz clock will yield a width that is one-fourth of that read with // a 16 MHz clock). each loop was empirically determined to take // approximately 23/20 of a microsecond with a 16 MHz clock. return width * (16000000UL / F_CPU) * 20 / 23;}

Something wrong with my code is that you have to have pulse (LOW->HIGH->LOW) return from each sensor to work. Without a pulse, "while" loops are infinite.

If you are uncertain of sensor pulse return, you have to add a counter to check "overload" and a break to exit each while loop. But, you will have minus precision on pulse width measure.