that's Carl with a C, but that's allright. OK here is my code:
int ultraSoundSignal = 8; // Ultrasound signal pin
int ultraSoundSignall = 7;
int val = 0;
int vall = 0;
int ultrasoundValue = 0;
int ultrasoundValuee = 0;
int timecount = 0; // Echo counter
int timecountt = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13
int Aen = 4;
int Aplus = 5;
int Amin = 6;
void setup() {
beginSerial(9600); // Sets the baud rate to 9600
pinMode(ledPin, OUTPUT); // Sets the digital pin as output
pinMode(Aen, OUTPUT);
pinMode(Aplus, OUTPUT);
pinMode(Amin, OUTPUT);
}
void loop() {
timecount = 0;
val = 0;
vall = 0;
pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output
pinMode(ultraSoundSignall, OUTPUT);
/* Send low-high-low pulse to activate the trigger pulse of the sensor
*/
digitalWrite(ultraSoundSignal, LOW); // Send low pulse
digitalWrite(ultraSoundSignall, LOW);
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
digitalWrite(ultraSoundSignall, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff
digitalWrite(ultraSoundSignall, LOW); // Holdoff
/* Listening for echo pulse
*/
pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundSignal); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
}
while(val == HIGH) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
timecount = timecount +1; // Count echo pulse time
}
pinMode(ultraSoundSignall, INPUT); // Switch signalpin to input
vall = digitalRead(ultraSoundSignall); // Append signal value to val
while(vall == LOW) { // Loop until pin reads a high value
vall = digitalRead(ultraSoundSignall);
}
while(vall == HIGH) { // Loop until pin reads a high value
vall = digitalRead(ultraSoundSignall);
timecountt = timecountt +1; // Count echo pulse time
}
/* Writing out values to the serial port
*/
ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue
//ultrasoundValuee = timecountt; // Append echo pulse time to ultrasoundValue
serialWrite('S'); // Example identifier for the sensor
printInteger(ultrasoundValue);
serialWrite(10);
serialWrite(13);
/* Lite up LED if any value is passed by the echo pulse
*/
if(timecount < 100){
digitalWrite(Aen, HIGH);
digitalWrite(Aplus, HIGH);
digitalWrite(Amin, LOW);
}
if(timecount > 100){
digitalWrite(Aen, HIGH); // Send low pulse
delay(5); // Wait for 2 microseconds
digitalWrite(Aen, LOW); // Send high pulse
delay(5); // Wait for 5 microseconds
digitalWrite(Aen, HIGH); // Holdoff
digitalWrite(Aplus, HIGH);
digitalWrite(Amin, HIGH);
}
if(timecount > 0){
digitalWrite(ledPin, HIGH);
}
/* Delay of program
*/
delay(100);
}
Now I know that I can't use 2 sets of while loops to read the two different sensors, but I don't know how to do it the right way. In the end i want to use the two sensors to keep an object aligned with a walking person in one direction. Please help me!