Array?

Hi Benoît,

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:

serialWrite('A'); // Example identifier for the sensor
printInteger(aultrasoundValue);
printInteger(bultrasoundValue);
serialWrite(10);

I was wondering how I might go about sepparating the streams being received on pins 6 and 7? sending some kind of array of the two values rather than their combined value.

all the code is pasted below incase you have time to take a look, I am sure there will be a million things wrong as I'm rather new to arduino.

cheers.

// Ultrasound Sensors

int aultraSoundSignal = 6; // US 1
int bultraSoundSignal = 7; // US 2
int aval = 0;
int bval = 0;
int aultrasoundValue = 0; //US1 Value
int bultrasoundValue = 0; //US2 Value
int atimecount = 0; // Echo counter
int btimecount = 0;
int ledPin = 13; // LED connected to digital pin 13

void setup() {
  beginSerial(9600);                  // Sets the baud rate to 9600
  pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
}

void loop() {
 atimecount = 0;
 btimecount = 0;
 aval = 0;
 bval = 0;
 pinMode(aultraSoundSignal, OUTPUT); // Switch signalpin to output
 pinMode(bultraSoundSignal, OUTPUT);

/* Send low-high-low pulse to activate the trigger pulse of the sensor
 * -------------------------------------------------------------------
 */

digitalWrite(aultraSoundSignal, LOW); // Send low pulse
digitalWrite(bultraSoundSignal, LOW);
delayMicroseconds(2); // Wait for 2 microsecond
digitalWrite(aultraSoundSignal, HIGH); // Send high pulse
digitalWrite(bultraSoundSignal, HIGH);
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(aultraSoundSignal, LOW); // Holdoff
digitalWrite(bultraSoundSignal, LOW);

/* Listening for echo pulse
 * -------------------------------------------------------------------
 */

pinMode(aultraSoundSignal, INPUT); // Switch signalpin to input
aval = digitalRead(aultraSoundSignal); // Append signal value to val
pinMode(bultraSoundSignal, INPUT); // Switch signalpin to input
bval = digitalRead(bultraSoundSignal);

while(aval == LOW) { // Loop until pin reads a high value
  aval = digitalRead(aultraSoundSignal);
  }

while(bval == LOW) { // Loop until pin reads a high value
  bval = digitalRead(bultraSoundSignal);
    
}

while(aval == HIGH) { // Loop until pin reads a high value
  aval = digitalRead(aultraSoundSignal);
  atimecount = atimecount +1;            // Count echo pulse time
  }
  while(bval == HIGH) { // Loop until pin reads a high value
  bval = digitalRead(bultraSoundSignal);
  btimecount = btimecount +1;            // Count echo pulse time
}

/* Writing out values to the serial port
 * -------------------------------------------------------------------
 */

aultrasoundValue = atimecount; // Append echo pulse time to ultrasoundValue
bultrasoundValue = btimecount;

serialWrite('A'); // Example identifier for the sensor
printInteger(aultrasoundValue);
printInteger(bultrasoundValue);
serialWrite(10);

/* Lite up LED if any value is passed by the echo pulse
 * -------------------------------------------------------------------
 */

if(atimecount+btimecount > 0){
  digitalWrite(ledPin, HIGH);
}

/* Delay of program
 * -------------------------------------------------------------------
 */

delay(100);
}