#include<Servo.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int pingPinTRI1 = 7;
int pingPinECHO1 = 8;
int pingPinTRI2 = 9;
int pingPinECHO2 = 10;
Servo myservo;
Servo myservo1;
Servo myservo2;
int avlb=15;
void setup()
{
myservo.attach(6);
myservo1.attach(9);
myservo2.attach(7);
pinMode(pingPinTRI1, OUTPUT);
pinMode(pingPinECHO1, INPUT);
pinMode(pingPinTRI2, OUTPUT);
pinMode(pingPinECHO2, INPUT);
lcd.begin(16,2);
Serial.begin(9600);
}
void loop()
{
display(avlb);
long duration1, cm1 , duration2 , cm2 ;
digitalWrite(pingPinTRI1, LOW);
delayMicroseconds(2);
digitalWrite(pingPinTRI1, HIGH);
delayMicroseconds(5);
digitalWrite(pingPinTRI1, LOW);
digitalWrite(pingPinTRI2, LOW);
delayMicroseconds(2);
digitalWrite(pingPinTRI2, HIGH);
delayMicroseconds(5);
digitalWrite(pingPinTRI2, LOW);
duration1=pulseIn(pingPinECHO1, HIGH);
cm1=microsecondsToCentimeters(duration1);
if(cm1>1 && cm1<5)
{
if(avlb!=0)
{
myservo.write(177);
myservo1.write(177);
jump1:
duration2=pulseIn(pingPinECHO2, HIGH);
cm2=microsecondsToCentimeters(duration2);
if(cm2>1 && cm2<5)
{
myservo.write(110);
avlb--;
display(avlb);
}
else
{
goto jump1;
}
}
delay(5000);
}
duration2=pulseIn(pingPinECHO2, HIGH);
cm2=microsecondsToCentimeters(duration2);
if(cm2>1 && cm2<5)
{
if(avlb!=15)
{
myservo.write(177);
myservo2.write(177);
jump2:
duration1=pulseIn(pingPinECHO1, HIGH);
cm1=microsecondsToCentimeters(duration1);
if(cm1>1 && cm1<5)
{
myservo.write(110);
avlb++;
display(avlb);
}
else
{
goto jump2;
}
delay(5000);
}
}
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
void display(int lots)
{
lcd.print("no.of lots ");
lcd.setCursor(0,1);
lcd.print("available : ");
lcd.print(lots);
}