SHARE
TWEET

Untitled

a guest Apr 25th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  4.  
  5. #include "HX711.h"
  6. const int LOADCELL_DOUT_PIN = 5;
  7. const int LOADCELL_SCK_PIN = 6;
  8. HX711 scale;
  9.  
  10. #define clk 2
  11. #define dt 3
  12. #define sw 4
  13. #define in1 7
  14. #define in2 8
  15. #define in3 9
  16. #define in4 10
  17. #define calibration_factor 1064.5 //Kalibracni faktor
  18.  
  19. volatile boolean TurnDetected;
  20. volatile boolean up;
  21. bool doonce = 0;
  22. char screen = 0;
  23. boolean changestate = 0;
  24. long weight;
  25. int pump1g = 20; //pocatecni hodnoty 1 pumpy
  26. int pump2g = 20; //pocatecni hodnoty 2 pumpy
  27.  
  28.  
  29. void isr0 ()  {
  30.   TurnDetected = true;
  31.   up = (digitalRead(clk) == digitalRead(dt));
  32. }
  33.  
  34. void setup() {
  35.   scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  36.   delay(2000);
  37.   scale.set_scale(calibration_factor); //Načtení kalibračního faktoru  
  38.   scale.tare(); //Za předpokladu, že na stupnici není při startu žádná hmotnost, resetujte váhu na 0
  39.   lcd.begin(20, 4); //
  40.   lcd.backlight(); // zapnuti podsviceni
  41.  
  42.   pinMode(sw, INPUT_PULLUP);
  43.   pinMode(clk, INPUT);
  44.   pinMode(dt, INPUT);
  45.   pinMode(in1, OUTPUT);
  46.   pinMode(in2, OUTPUT);
  47.   pinMode(in3, OUTPUT);
  48.   pinMode(in4, OUTPUT);
  49.   digitalWrite(in1, LOW);
  50.   digitalWrite(in2, LOW);
  51.   digitalWrite(in3, LOW);
  52.   digitalWrite(in4, LOW);
  53.   attachInterrupt (0, isr0, RISING);
  54. }
  55.  
  56. void loop() {
  57.   if (TurnDetected) {
  58.     delay(200);
  59.     doonce = 0;
  60.     if (changestate == 0) {
  61.       if (up) {
  62.         screen++;
  63.         if (screen > 3) {
  64.           screen = 3;
  65.         }
  66.       }
  67.       else {
  68.         screen = screen - 1;
  69.         if (screen < 0) {
  70.           screen = 0;
  71.         }
  72.       }
  73.     }
  74.     else {
  75.       if (up) {
  76.         switch (screen) {
  77.           case 0: pump1g = pump1g + 10;
  78.           break;
  79.           case 1: pump2g = pump2g + 10;
  80.           break;
  81.         }
  82.       }
  83.       else {
  84.         switch (screen) {
  85.           case 0: pump1g = pump1g - 10;
  86.           break;
  87.           case 1: pump2g = pump2g - 10;
  88.           break;
  89.  
  90.         }
  91.       }
  92.     }
  93.     TurnDetected = false;
  94.   }
  95.  
  96.  
  97.   if (digitalRead(sw) == LOW) {
  98.     delay(200);
  99.     changestate = !changestate;
  100.     doonce = 0;
  101.   }
  102.  
  103.   if (screen == 0 && doonce == 0) {
  104.     lcd.clear();
  105.     lcd.print("1 Slozka");
  106.     lcd.setCursor(0, 1);
  107.     lcd.print(pump1g);
  108.     lcd.setCursor(3, 1);
  109.     lcd.print("g");
  110.     if (changestate == 0) {
  111.     lcd.setCursor(9, 0 );
  112.     lcd.print("Zmenit?");
  113.     }
  114.     doonce = 1;
  115.   }
  116.  
  117.   if (screen == 1 && doonce == 0) {
  118.     lcd.clear();
  119.     lcd.print("2 Slozka");
  120.     lcd.setCursor(0, 1);
  121.     lcd.print(pump2g);
  122.     lcd.setCursor(3, 1);
  123.     lcd.print("g");
  124.     if (changestate == 0) {
  125.       lcd.setCursor(9, 0 );
  126.       lcd.print("Zmenit?");
  127.       }
  128.     doonce = 1;
  129.   }
  130.  
  131.  
  132.   if (screen == 2 && doonce == 0) {
  133.     lcd.clear();
  134.     if (changestate == 0) {
  135.       lcd.print("Zacit davkovat?");
  136.       lcd.setCursor(0, 1);
  137.        lcd.print("Spravny pomer?");
  138.       doonce = 1;
  139.     }
  140.  
  141.  
  142.  
  143.     else {
  144.       lcd.print("Cekejte !");
  145.       delay(2000);
  146.       lcd.clear();
  147.  
  148.       //tady je pumpa 1
  149.       lcd.print("Pumpa 1 Zapnuta");
  150.       digitalWrite(in1, HIGH);
  151.       while (scale.read() < pump1g) {      }
  152.       lcd.clear();
  153.       lcd.print(pump1g);
  154.       lcd.print("g");
  155.       delay((pump1g/12)*1000);
  156.       digitalWrite(in1, LOW);
  157.       delay(2000);
  158.       weight = scale.read();
  159.       delay(100);
  160.       lcd.clear();
  161.  
  162.       //tady je pumpa 2
  163.       lcd.print("Pumpa 2 Zapnuta");
  164.       digitalWrite(in3, HIGH);
  165.       while (scale.read() - weight < 3000) {     }
  166.       lcd.clear();
  167.       lcd.print(pump2g);
  168.       lcd.print("g");
  169.       delay((pump2g/12)*1000);
  170.       digitalWrite(in3, LOW);
  171.       delay(2000);
  172.  
  173.       changestate = 0;
  174.     }
  175.   }
  176. }
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
 
Top