right so i have changed the code so that it uses the pulseIn function, it uploads to the board and works for a few seconds but doesn't sustain itself, i hope i haven't broken my adruino!
here's the code:
int pingpina = 7; // Ultrasound signal pin
int pingpinb = 8; // Ultrasound signal pin
long vala;
long valb;
int ledPin = 13; // LED connected to digital pin 13
boolean pulseAin, pulseBin;
void setup() {
beginSerial(9600); // Sets the baud rate to 9600
pinMode(ledPin, OUTPUT); // Sets the digital pin as output
}
void loop() {
pinMode(pingpina, OUTPUT);
pinMode(pingpinb, OUTPUT); // Switch signalpin to output
/* Send low-high-low pulse to activate the trigger pulse of the sensor
* -------------------------------------------------------------------
*/
digitalWrite(pingpina, LOW); // Send low pulse
digitalWrite(pingpinb, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(pingpina, HIGH); // Send high pulse
digitalWrite(pingpinb, HIGH); // Send high pulse
delayMicroseconds(5);
digitalWrite(pingpina, LOW); // Send low pulse
digitalWrite(pingpinb, LOW);
//
pulseAin = false;
pulseBin = false;
pinMode(pingpina, INPUT); // Switch signalpin A to input
pinMode(pingpinb, INPUT); // Switch signalpin B to input
while(pulseAin == false || pulseBin == false) { // Loop until both pins reads a high value
if( digitalRead(pingpina) != 0 && pulseAin == false){
vala = pulseIn(pingpina, HIGH);
pulseAin = true;
}
if( digitalRead(pingpinb) != 0 && pulseBin == false){
valb = pulseIn(pingpinb, HIGH);
pulseBin = true;
}
}
/* Writing out values to the serial port
* -------------------------------------------------------------------
*/
// do the scalling of your results here
Serial.print("Sensor A value =");
Serial.println(vala);
Serial.print("Sensor b value =");
Serial.println(valb);
delay(40);
}
it seems like it works but it just doesn't last very long and sort of crashes! does any know what's going wrong? Any help will be greatly appreciated.
cheers