heres is what i have now but still things are wrong now the act light on the sensors flashes twice at the start lights up the led but must just switch off or get confused.
/* New Variables */
int delay_time = 20; // delay for this amount each write cycle.
byte printing_byte = 0;
int pingpina = 7; // Ultrasound signal pin
int pingpinb = 8; // Ultrasound signal pin
int vala = 0;
int valb = 0;
int pingValuea = 0;
int pingValueb = 0;
int timecounta = 0;
int timecountb = 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() {
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
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(pingpina, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(pingpina, LOW); // Holdoff
delayMicrosenconds(10); // delay between the sends of pulse to each sensor
digitalWrite(pingpinb, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(pingpinb, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(pingpinb, LOW); // Holdoff
/* Listening for echo pulse
*/
pinMode(pingpina, INPUT); // Switch signalpin to input
vala = digitalRead(pingpina); // Append signal value to val
while(vala == LOW) { // Loop until pin reads a high value
vala = digitalRead(pingpina);
delayMicroseconds(10);
pinMode(pingpinb, INPUT); // Switch signalpin to input
valb = digitalRead(pingpinb); // Append signal value to val
while(valb == LOW) { // Loop until pin reads a high value
valb = digitalRead(pingpinb);
}
while(vala == HIGH) { // Loop until pin reads a high value
vala = digitalRead(pingpina);
timecounta = timecounta +1;
delayMicroseconds(10);
while(valb == HIGH) { // Loop until pin reads a high value
valb = digitalRead(pingpinb);
timecountb = timecountb +1; // Count echo pulse time
}
/* Writing out values to the serial port
*/
pingValuea = timecounta; // Append echo pulse time to ultrasoundValue
/* BEGIN EDITED CODE */
pingValuea = pingValuea - 14;
pingValuea = pingValuea / 5;
if(pingValuea > 127) {
}
else {
printing_byte = pingValuea;
Serial.print(printing_byte);
}
/* END EDITED CODE */
/* Lite up LED if any value is passed by the echo pulse
*/
if(timecounta > 0){
digitalWrite(ledPin, HIGH);
}
/* Delay of program
*/
delay(40);
}