yeah i changed the brackets and still 0s and 1s and the sensors out put the same number at the same time so surely some things going wrong.
so this is the other piece of code that sort of works. In the serial monitor it gives out randomy numbers, does anyone know which way is the best to go.
int pingpina = 7; // Ultrasound signal pin
int pingpinb = 8; // Ultrasound signal pin
int vala;
int valb;
int pingValuea = 0;
int pingValueb = 0;
int timecounta;
int timecountb;
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() {
timecounta = 0;
timecountb = 0;
vala = 0;
valb = 0;
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);
//
pinMode(pingpina, INPUT); // Switch signalpin A to input
pinMode(pingpinb, INPUT); // Switch signalpin B to input
vala = digitalRead(pingpina);
while(vala == LOW) {
vala = digitalRead(pingpina);
}
valb = digitalRead(pingpinb);
while(valb == LOW) {
valb = digitalRead(pingpinb);
}
while(vala == HIGH) {
vala = digitalRead(pingpina);
timecounta = timecounta +1;
}
while(valb == HIGH) {
valb = digitalRead(pingpinb);
timecountb = timecountb +1;
}
/* Writing out values to the serial port
* -------------------------------------------------------------------
*/
pingValuea = timecounta;
pingValueb = timecountb;
Serial.print("Sensor A value = ");
Serial.println(pingValuea);
Serial.print("Sensor b value = ");
Serial.println(pingValueb);
delay (10); // put any delay you need here to slow down the loop
}