1#include "HX711.h"
2#include"math.h"
3#include <EEPROMex.h>
4#include <EEPROMVar.h>
5#include <LiquidCrystal.h>
6#define BUTTON 7
7#define LED 13
8#define TAREBUTTON 10
9#define buzzer 8
10
11
12LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
13
14HX711 scale(A2, A3);
15
16long somma1=0;
17float I=0;
18int a;
19float b;
20float calibval1;
21float calibval2;
22float media2=0;
23float media1=0;
24long somma2=0;
25float pmax= 900;
26int val=0;
27int val1=0;
28float t =0;
29float g=0;
30void setup() {
31 scale.set_scale();
32 scale.tare();
33 pinMode (buzzer, OUTPUT);
34 tone(buzzer,440,1000);
35 delay(500);
36 noTone(buzzer);
37 delay(200);
38 tone (buzzer,330,1000);
39 delay(1000);
40 noTone(buzzer);
41Serial.begin (9600);
42 lcd.begin(16, 2);
43 lcd.print ("Fede Bil");
44 lcd.setCursor( 0,1);
45 lcd.print ("ver.1.0 :)");
46 for (int positionCounter = 0; positionCounter < 6; positionCounter++) {
47
48 lcd.scrollDisplayRight();
49
50 delay(450);}
51 for (int positionCounter = 0; positionCounter < 6; positionCounter++) {
52
53 lcd.scrollDisplayLeft();
54
55 delay(450);}
56 delay(3000);
57 lcd.clear ();
58 lcd.print ("Press Button 2");
59 lcd.setCursor(0,1);
60 lcd.print("to calibrate");
61 delay(1500);
62 pinMode(LED, OUTPUT);
63 pinMode (TAREBUTTON,OUTPUT);
64 pinMode(BUTTON, INPUT);
65val=digitalRead (BUTTON);
66if (val==HIGH){
67 tone(buzzer,1047,1000);
68digitalWrite(LED, HIGH);
69calibrazione();}
70else {
71 tone(buzzer,660,500);
72Serial.println (EEPROM.readFloat(10));
73calibval2= (EEPROM.readFloat(10));
74Serial.print ("calibval2=");
75Serial.println (calibval2);
76scale.set_scale (calibval2);
77}}
78
79void loop() {
80
81pippo: I= (scale.get_units(10));
82Serial.println(I);
83if (I < 1 &&I>0)
84{ val1= digitalRead (TAREBUTTON);
85if (val1==HIGH){
86 tone(buzzer,622,1000);
87 lcd.clear();
88 lcd.print ("Tara");
89 delay (1000);
90 t= scale.get_units(10);
91 g=round(t);
92 scale.tare();}
93 lcd.clear();
94 lcd.print("d=0,5g");
95
96 lcd.setCursor(0,1);
97 lcd.print("0.00");
98 lcd.setCursor(9,0);
99 lcd.print ("d=0.2g");
100 lcd.setCursor (9,1);
101 lcd.print(I);
102 delay(500);
103 Serial.println ("0.00");
104 val=digitalRead (BUTTON);
105 if (val==HIGH){
106 tone(buzzer,1047,500);
107digitalWrite(LED, HIGH);
108menu();}
109else {
110}
111 goto pippo;
112}
113val1= digitalRead (TAREBUTTON);
114if (val1==HIGH){
115 tone(buzzer,622,1000);
116 lcd.clear();
117 lcd.print ("Tara");
118 delay (1000);
119 t =scale.get_units(10);
120 g=round(t);
121 scale.tare();
122 val=digitalRead (BUTTON);
123 if (val==HIGH){
124 tone(buzzer,1047,500);
125digitalWrite(LED, HIGH);
126menu();}
127else {
128}}
129 int c= (I*10);
130 int e = (I*10);
131
132 int peso_div = (e+1)-((e+1)%2);
133int peso_div_5 = (c+2)-((c+2)%5);
134 float f = (peso_div);
135 float peso2 = (f/10);
136 float d = (peso_div_5);
137 float pesofin=(d/10);
138 if (pesofin > pmax)
139 {tone(buzzer,1047,2000);
140 lcd.clear();
141 lcd.print ("Overload");
142 goto pippo;}
143 lcd.clear();
144 lcd.setCursor (0,0);
145 lcd.print ("d=0,5g");
146 lcd.setCursor(0, 1);
147 lcd.print (pesofin);
148 lcd.setCursor(9,0);
149 lcd.print ("d=0.2g");
150 lcd.setCursor (9,1);
151 lcd.print (peso2);
152 delay(150);
153 val=digitalRead (BUTTON);
154if (val==HIGH){
155 tone(buzzer,1047,500);
156digitalWrite(LED, HIGH);
157lcd.clear();
158menu();}
159else {
160}
161}
162