SHARE
TWEET

Untitled

a guest Nov 15th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<Ultrasonic.h>
  2.  
  3. Ultrasonic ultrasonic(5,6);
  4.  
  5. Ultrasonic ultrasonic2(11,10);
  6.  
  7.  
  8. unsigned long currentMillis =0,t1,t2;
  9.  
  10. int d1,d2,c;
  11.  
  12. boolean ex=0,en=0,in;
  13.  
  14. void setup()
  15. {
  16.   pinMode(4,OUTPUT);
  17.   digitalWrite(4,HIGH);
  18.   Serial.begin(9600);
  19.   delay(5000);
  20.   Serial.println("WELCOME TO AUTOMATION !!");
  21.   Serial.println(ultrasonic.distanceRead());
  22.   Serial.println(ultrasonic2.distanceRead());
  23. }
  24.  
  25. void loop()
  26. {
  27.   currentMillis=(millis())%100;
  28.   d1=ultrasonic.distanceRead();
  29.   d2=ultrasonic2.distanceRead();
  30.  
  31.   if(currentMillis==0)
  32.   {
  33.     Serial.print("Count is :");
  34.     Serial.println(c);
  35.     Serial.println(d1);
  36.     Serial.println(d2);
  37.   }
  38.  
  39.  
  40.   if(d1<=15 && d2<=15)
  41.   {
  42.     c=c;
  43.   }
  44.   else if(d1<=15)
  45.   {
  46.     if(en==1)
  47.     {
  48.       c++;
  49.       en=0;
  50.     }
  51.     else ex=1;
  52.   }
  53.  
  54.   else if(d2<=15)
  55.   {
  56.     if(ex==1)
  57.     {
  58.       c--;
  59.       ex=0;
  60.     }
  61.     else en=0;
  62.   }
  63.  
  64. }
RAW Paste Data
Top