Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HX711.h" //libreria per il funzionamento del modulo che interfaccia la cella con arduino(hx711)
- #define calibration_factor 4300 //fattore di calibrazione ricavato con lo sketch di calibrazion della cella
- #define DOUT 2 //ingresso cella su arduino
- #define CLK 3 // ingresso cella su arduino
- HX711 scale(DOUT, CLK);
- char del = 0;
- float units;
- void(* resetFunc) (void) = 0; //creo una fuznione che riavvia l'esecuzione del codice
- void setup()
- {
- Serial.begin(9600);
- scale.set_scale(calibration_factor);
- scale.tare();
- Serial.println("Read:");
- }
- int val1() // DELAY A UN SECONDO
- {
- while(7==7) //uso questa while per far ripetere la funzione fin quando non ricevo un input da vb
- {
- units = scale.get_units();
- float libbre = scale.get_units();
- float kg = (libbre/2.2046);
- Serial.print(kg, 1);
- Serial.println(" kg");
- delay (1000); //tempo tra una lettura ed un altra
- if(Serial.available()) //controllo se la seriale è disponibile
- {
- char ext = Serial.read(); //leggo dalla seriale
- if (ext == '2') // se ext è = 2 metto in pausa
- break;
- if (ext == 'z') // se ext = z riavvio la funzione
- resetFunc(); // z e 2 vengono inviate alla seriale di arduino dai bottoni pausa(2) e disconetti(z)
- }
- }
- }
- int val05() // DELAY A MEZZO SECONDO
- {
- while(7==7)
- {
- units = scale.get_units();
- float libbre = scale.get_units();
- float kg = (libbre/2.2046);
- Serial.print(kg, 1);
- Serial.println(" kg");
- delay (500);
- if(Serial.available())
- {
- char ext = Serial.read();
- if (ext == '2')
- break;
- if (ext == 'z')
- resetFunc();
- }
- }
- }
- int val15() // DELAY A UN SECONDO E MEZZO
- {
- while(7==7)
- {
- units = scale.get_units();
- float libbre = scale.get_units();
- float kg = (libbre/2.2046);
- Serial.print(kg, 1);
- Serial.println(" kg");
- delay (1500);
- if(Serial.available())
- {
- char ext = Serial.read();
- if (ext == '2')
- break;
- if (ext == 'z')
- resetFunc();
- }
- }
- }
- int val2() // DELAY A DUE SECONDI
- {
- while(7==7)
- {
- units = scale.get_units();
- float libbre = scale.get_units();
- float kg = (libbre/2.2046);
- Serial.print(kg, 1);
- Serial.println(" kg");
- delay (2000);
- if(Serial.available())
- {
- char ext = Serial.read();
- if (ext == '2')
- break;
- if (ext == 'z')
- resetFunc();
- }
- }
- }
- void loop()
- {
- del = Serial.read();
- switch (del)
- {
- case '1':
- val1();
- case '3':
- val05();
- case '4':
- val15();
- case '5':
- val2();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement