pulseIn code for ping?
I am using a Parallax ping sensor on a servo connected to a Arduino 328. I am trying to get the ping sensor to ping as close to continious as possible while the servo sweeps. But the servo stops everytime the Parallax sensor pings. So to do a 180* sweep it takes roughly a minute and a half. I am being told that the pulseIn (return info) is a disruptive declaration, IS THERE ANY WAY AROUND THIS???
Thanks 4 any insight!!
jamesonh20
#include <Servo.h>
const int pingPin = 7;
const int servoPin = 9;
const int LED = 13;
Servo myservo; // create servo object to control a servo
int pos = 0; // current servo position
int dir = 1; // current servo direction
int ping (void) {
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH); // hello, ping)))
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
return pulseIn(pingPin, HIGH) / 148; // wait for echo and return inches
}
void setup() {
myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop (void) {
int inches;
if (pos == 0) dir = 1;
else if (pos == 180) dir = -1;
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(14); // waits 14ms for the servo to reach the position
inches = ping (); // anybody there?
Serial.print (inches);
Serial.println (" inches.");
if (inches < 11) // if anything's within 10 inches
digitalWrite (LED, HIGH); // turn led on
else // otherwise
digitalWrite (LED, LOW); //turn led off
pos += dir; // advance servo position
}
Thanks 4 any insight!!
jamesonh20

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Jamesonh20
Go to "Stamps In Class", Ping)))Dar - a Radar Style Display.· It contains code for the BS2 and Propeller (spin).· I got ping to scan (using Propeller) from 0-180 in about 4 seconds at about ~ 1.4 degrees of resolution.·· That's about 128 "PINGS" in 180 degrees.· If you change it to 2.8 degrees of resolution, Ping would scan 0-180 degrees in about 2 seconds.· Of course, this was using spin and no Floating Point (FP) Math.· I could speed this up by using PASM, but I have no time.· You might be able to decipher the code and implement to Arduino.· Good luck.
Bob