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