Advertisement
Guest User

code load cell my

a guest
Feb 24th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "HX711.h" //libreria per il funzionamento del modulo che interfaccia la cella con arduino(hx711)
  2.  
  3. #define calibration_factor 4300 //fattore di calibrazione ricavato con lo sketch di calibrazion della cella
  4. #define DOUT 2 //ingresso cella su arduino
  5. #define CLK 3 // ingresso cella su arduino
  6. HX711 scale(DOUT, CLK);
  7. char del = 0;
  8. float units;
  9. void(* resetFunc) (void) = 0; //creo una fuznione che riavvia l'esecuzione del codice
  10. void setup()
  11. {
  12.   Serial.begin(9600);
  13.   scale.set_scale(calibration_factor);
  14.   scale.tare();
  15.   Serial.println("Read:");
  16. }    
  17.  
  18.  
  19.  
  20.  
  21. int val1() //  DELAY A UN SECONDO
  22. {
  23.       while(7==7) //uso questa while per far ripetere la funzione fin quando non ricevo un input da vb
  24.       {  
  25.         units = scale.get_units();
  26.         float libbre = scale.get_units();
  27.         float kg = (libbre/2.2046);
  28.         Serial.print(kg, 1);
  29.         Serial.println(" kg");
  30.         delay (1000); //tempo tra una lettura ed un altra
  31.         if(Serial.available()) //controllo se la seriale è disponibile
  32.         {
  33.           char ext = Serial.read(); //leggo dalla seriale
  34.           if (ext == '2') // se ext è = 2 metto in pausa
  35.           break;
  36.           if (ext == 'z') // se ext = z riavvio la funzione
  37.           resetFunc(); // z e 2  vengono inviate alla seriale di arduino dai bottoni pausa(2) e disconetti(z)
  38.      }
  39.   }
  40. }
  41.  
  42.  
  43.  
  44.  
  45.   int val05() // DELAY A MEZZO SECONDO
  46.  {
  47.       while(7==7)
  48.    {
  49.     units = scale.get_units();
  50.     float libbre = scale.get_units();
  51.     float kg = (libbre/2.2046);
  52.     Serial.print(kg, 1);
  53.     Serial.println(" kg");
  54.     delay (500);
  55.     if(Serial.available())
  56.     {
  57.       char ext = Serial.read();
  58.       if (ext == '2')
  59.       break;
  60.       if (ext == 'z')
  61.       resetFunc();
  62.      }
  63.     }
  64.   }
  65.  
  66.  
  67.  
  68.  
  69.   int val15() // DELAY A UN SECONDO E MEZZO
  70.  {
  71.       while(7==7)
  72.    {
  73.     units = scale.get_units();
  74.     float libbre = scale.get_units();
  75.     float kg = (libbre/2.2046);
  76.     Serial.print(kg, 1);
  77.     Serial.println(" kg");
  78.     delay (1500);
  79.     if(Serial.available())
  80.     {
  81.       char ext = Serial.read();
  82.       if (ext == '2')
  83.       break;
  84.       if (ext == 'z')
  85.       resetFunc();
  86.      }
  87.     }
  88.   }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.   int val2() // DELAY A DUE SECONDI
  95.  {
  96.       while(7==7)
  97.    {
  98.     units = scale.get_units();
  99.     float libbre = scale.get_units();
  100.     float kg = (libbre/2.2046);
  101.     Serial.print(kg, 1);
  102.     Serial.println(" kg");
  103.     delay (2000);
  104.     if(Serial.available())
  105.     {
  106.       char ext = Serial.read();
  107.       if (ext == '2')
  108.       break;
  109.       if (ext == 'z')
  110.       resetFunc();    
  111.                      
  112.      
  113.      }
  114.     }
  115.   }
  116.  
  117.  
  118.  
  119. void loop()
  120. {
  121.    
  122.    del = Serial.read();
  123.    switch (del)
  124.     {
  125.       case '1':
  126.          val1();
  127.       case '3':
  128.          val05();
  129.       case '4':
  130.          val15();
  131.       case '5':
  132.          val2();    
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement