ive tried a bit on this code.... but this wouldnt give any readings on the SERIAL port
#include <LiquidCrystal.h>
#include <Servo.h>
#include <NewPing.h>
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
Servo myservo;
int pos = 0;
int it = 10;
int lld;
LiquidCrystal lcd(6,5,7,4,3,2);
void setup() {
lcd.begin(16, 2);
myservo.attach(9);
Serial.begin(9600);
delay(3000);
}
void loop() {
int i = 0;
int t = 0;
float a1 = 0;
float a2 = 0;
float a;
for (i = 0; i < 180; i ++)
{
unsigned int uS = sonar.ping();
myservo.write(i);
delay(20);
for (t = 0; t < it; t++)
{
uS = sonar.ping();
a1 = uS/US_ROUNDTRIP_CM + a1;
delay(30);
}
a1 = a1 / (it-1);
t = 0;
}
for (i = 180; i > 0; i --)
{
unsigned int uS = sonar.ping();
myservo.write(i);
delay(20);
for (t = 0; t < it; t++)
{
uS = sonar.ping();
a2 = uS/US_ROUNDTRIP_CM + a2;
delay(30);
}
a2 = a2 / (it-1);
t = 0;
a = (a1+a2)/2;
Serial.println(a);
a = 0;
a2 = 0;
a1 = 0;
}
}