Multiple ultrasonic sensor reading, port manipulation problem [SOLVED]

EDIT: Solved.

Thanks to precious help this is solved. I had indeed "datasheet" that had misledaing information about way HC-SR04 works. I changed the code to measure pulse high time as usually and it works now, nice. I have tested reading two sensors at once and get values to fluctuate only some millimeters. I'll try to add some more sensors and post how it works. Working code attached, sorry it's  in finnish but it is quite clear what it does.

 

Hello again,

I have been experimenting with ultrasonic sensors lately. When using several sensors I thought it would be nice to read them at once, not one after one. I didn't find the code so i tried to do one myself. Example code triggers both sensors and starts reading PIND to notice change in inputs(counter is inceremented every loop). When change is noticed, program continues reading port.

 

However values won't change following change in object distance.

multisensor.jpg

Picture is from version of  program where i use micros() to read time.

Code: Variables are in finnish, sorry :) Comments in english. Any input would be appreciated. REMOVED

 

New code that works, need little developing still for accuracy:

#define trigPin 12
#define echoPin 7
#define echoPin2 6

byte eka = 0;
unsigned long ekaAika = 0;
byte toka = 0;
unsigned long tokaAika = 0;


void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
   pinMode(echoPin2, INPUT);
//DDRD = B00000010;  // sets Arduino pins 2 to 7 as inputs, pin 0 as input
}

void loop() {
  byte portti = B11000000;
  byte maski =  B11000000;
  byte lukema = B11000000;
  unsigned long aika = 0;
 
  digitalWrite(trigPin, HIGH); // aktivoidaan sensorit, molempien
  delayMicroseconds(20); // triggerit kytketty samaan pinniin
  digitalWrite(trigPin, LOW);
  while((PIND & maski) != maski){
   
  }
  while(lukema == portti)// luetaan inputit kunnes joku pinneistä
                          // saa signaalin
  {
  lukema = PIND & maski; //luetaan maskin avulla vain halutut pinnit
  aika++;                // kasvatetaan laskuria
}
eka = lukema;       //tallentaan missä pinnissä signaali
ekaAika = aika;

portti = lukema;

  while(lukema == portti){
  lukema = PIND & maski;
  aika++;
}
toka = lukema;
tokaAika = aika;



 
 
    //Serial.println("Out of range");
 
  //else {
   Serial.print(eka);
   Serial.println(" sensori");
      Serial.print(ekaAika);
   Serial.println(" aika");
      Serial.print(toka);
   Serial.println(" sensori2");
      Serial.print(tokaAika);
   Serial.println(" aika2");
  
   Serial.println(" XXX");
   portti = B11000000;
  maski = B11000000;
  aika = 0;
  lukema = B11000000;
  //}
  delay(500);
}