SHARE
TWEET

Doluluk Orani Kalan Zaman Göstergesi

papuc111 Apr 25th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // ---------------------------------------------------------------------------
  3. // Example NewPing library sketch that does a ping about 20 times per second.
  4. // ---------------------------------------------------------------------------
  5.  
  6. #include <NewPing.h>
  7.  
  8. #define TRIGGER_PIN  7  // Trigger Ayagi
  9. #define ECHO_PIN     6  // Echo Ayagi
  10. #define MAX_DISTANCE 150 // En uzun ayarlanacak mesafe, 400-500 cm ya kadar ayarlanabilir
  11. #define MIN_DISTANCE 10    // En yakin mesafe
  12. // Pinzuweisung der LED´s
  13. byte led20 = 2;   // LED 20%
  14. byte led50 = 3;   // LED 50%
  15. byte led75 = 4;   // LED 75%
  16. byte led100 = 5;  // LED 100%
  17.  
  18. // Doluluk orani led göstergesi
  19. const int levelmin = 20;
  20. const int levelhalb = 50;
  21. const int level75 = 75;
  22. const int levelvoll = 100;
  23. int timer1 ;
  24. int timer2 ;
  25.  
  26.  
  27. bool flag;  // Yardimci ezberleyici
  28. int level;  // Doluluk Seviyesi
  29. uint32_t startzeit, messzeit, Restzeit;
  30. uint32_t delayvoll;   // Tam dolu durumda geciktirme
  31.  
  32. // Instanz New Ping
  33. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
  34.  
  35. void setup() {
  36.   Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  37.   pinMode(led20, OUTPUT);
  38.   pinMode(led50, OUTPUT);
  39.   pinMode(led75, OUTPUT);
  40.   pinMode(led100, OUTPUT);
  41.  
  42. }
  43.  
  44. void loop() {
  45.   delay(50);   // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  46.   //  auslesen und scalieren auf 0-100%
  47.   level = map(sonar.ping_cm(), MIN_DISTANCE, MAX_DISTANCE, 100, 0);
  48.  
  49.   if (level > levelmin)digitalWrite(led20, HIGH);
  50.   else digitalWrite(led20, LOW);
  51.  
  52.   if (level > levelhalb)digitalWrite(led50, HIGH);
  53.   else digitalWrite(led50, LOW);
  54.  
  55.   if (level > level75)digitalWrite(led75, HIGH);
  56.   else {
  57.     digitalWrite(led75, LOW);
  58.     if (!flag) {  // einmal messen
  59.       messzeit = millis() - startzeit;    // Ölcme zamani
  60.       flag = true;  // es ist gemessen
  61.     }
  62.   }
  63.  
  64.   if (level >= levelvoll) {
  65.     if (millis() - delayvoll > 1000UL) { // Doluluk belirleme
  66.       digitalWrite(led100, HIGH);
  67.       startzeit = millis(); // Ölcme zamani baslangic belirleme
  68.       flag = false;
  69.       messzeit = 0;
  70.      
  71.       Restzeit = 0 ;
  72.           }
  73.   }
  74.   else {
  75.     digitalWrite(led100, LOW);
  76.     delayvoll = millis();   // Tam dolu olursa Zamani Resetle
  77.   }
  78.  
  79.   Serial.print("Level: ");
  80.   Serial.print(level); // Send ping, get distance in cm and print result (0 = outside set distance range)
  81.   Serial.print("%");
  82.   Serial.print ("  Messzeit ");// Olculen Zaman (25% Bosalana kadar gecen süreyi yaz ve ezberle)
  83.   Serial.print(messzeit);
  84.   Serial.print ("  Behälter vermutlich leer in "); // Depo tahminen bosalacak süre :
  85.   Serial.print (messzeit/1000*3); Serial.println("Sekunden"); // Saniyede
  86.  
  87.  
  88.    
  89.  
  90. // delay(1000);
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top