forked from arzaman/Open-ArdBir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Funzioni.h
196 lines (175 loc) · 5.06 KB
/
Funzioni.h
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
float ConvertiCtoF(float& Num){
Num = (Num*1.8)+32; // Converto in °F
}
int ConvertiCtoF(int& Num){
Num = (Num*1.8)+32; // Converto in °F
}
float ConvertiFtoC(float& Num){
Num = (Num-32)/1.8; // Converto in °C
}
int ConvertiFtoC(int& Num){
Num = (Num-32)/1.8; // Converto in °C
}
float Arrotonda025(float& Num){
int Appoggio;
// Appoggio la parte intera
Appoggio = (int)int(Num);
// Arrotondo il valore con peso 0.25
Num=Appoggio+int((Num-Appoggio)*1000/225)*0.25;
}
/*
float change_set(float& set_change,int upper_limit, int lower_limit, float step_size){
// Increase set
if (btn_Repeat(Button_up)){
if (set_change >= upper_limit) set_change = upper_limit;
if (set_change < lower_limit) set_change = lower_limit;
if (set_change < upper_limit)set_change += step_size;
}
// decrease set
if (btn_Repeat(Button_dn)){
if (set_change <= lower_limit) set_change = lower_limit;
if (set_change > upper_limit) set_change = upper_limit;
if (set_change > lower_limit)set_change -= step_size;
}
}
int change_set(int& set_change, int upper_limit, int lower_limit, int step_size){
// Increase set
if (btn_Repeat(Button_up)){
if (set_change >= upper_limit) set_change = upper_limit;
if (set_change < lower_limit) set_change = lower_limit;
if (set_change < upper_limit)set_change += step_size;
}
// decrease set
if (btn_Repeat(Button_dn)){
if (set_change <= lower_limit) set_change = lower_limit;
if (set_change > upper_limit) set_change = upper_limit;
if (set_change > lower_limit)set_change -= step_size;
}
}
int change_set(byte& set_change, int upper_limit, int lower_limit, int step_size){
// Increase set
if (btn_Repeat(Button_up)){
if (set_change >= upper_limit) set_change = upper_limit;
if (set_change < lower_limit) set_change = lower_limit;
if (set_change < upper_limit)set_change += step_size;
}
// decrease set
if (btn_Repeat(Button_dn)){
if (set_change <= lower_limit) set_change = lower_limit;
if (set_change > upper_limit) set_change = upper_limit;
if (set_change > lower_limit)set_change -= step_size;
}
}
int change_up_dwn(int& change,int upper_limit,int lower_limit){
// Increase set temp
if (btn_Repeat(Button_up)){
change++;
if (change > upper_limit)change = upper_limit;
}
// decrease temp
if (btn_Repeat(Button_dn)){
change--;
if ( change < lower_limit) change = lower_limit;
}
}
// change between upper and lower limit using up down buttons
float change_up_dwn(float& change, int upper_limit, int lower_limit, float weight){
// Increase set
if (btn_Repeat(Button_up)){
change+=weight;
if (change > upper_limit)change = upper_limit;
}
// decrease temp
if (btn_Repeat(Button_dn)){
change-=weight;
if (change < lower_limit)change = lower_limit;
}
}
*/
int Set(int& Set, int Up, int Low, int Step, long Timer, byte Verso){
int step_size;
int ControllaPulsante;
delay(35);
if(Verso==1){
if(Set<Low)Set=Low;
if(Set>=Up)Set=Up;
ControllaPulsante=digitalRead(Button_up);
}
if(Verso==2){
if(Set>Up)Set=Up;
if(Set<=Low)Set=Low;
ControllaPulsante=digitalRead(Button_dn);
}
if(ControllaPulsante==0 && Verso!=0){
if(((millis()-Timer)/1000)>=4)step_size=(Step*10);
else{
if(((millis()-Timer)/1000)>=2)step_size=(Step*5);
else step_size=Step;
}
if(Verso==1){
if (Set+step_size>Up)Set=Up;
else Set+=step_size;
}else if(Verso==2){
if (Set-step_size<Low)Set=Low;
else Set-=step_size;
}
}
}
float Set(float& Set, int Up, int Low, float Step, long Timer, byte Verso){
float step_size;
int ControllaPulsante;
delay(35);
if(Verso==1){
if(Set<Low)Set=Low;
if(Set>=Up)Set=Up;
ControllaPulsante=digitalRead(Button_up);
}
if(Verso==2){
if(Set>Up)Set=Up;
if(Set<=Low)Set=Low;
ControllaPulsante=digitalRead(Button_dn);
}
if(ControllaPulsante==0 && Verso!=0){
if(((millis()-Timer)/1000)>=4)step_size=(Step*20.0);
else{
if(((millis()-Timer)/1000)>=2)step_size=(Step*4.0);
else step_size=Step;
}
if(Verso==1){
if (Set+step_size>Up)Set=Up;
else Set+=step_size;
}else if(Verso==2){
if (Set-step_size<Low)Set=Low;
else Set-=step_size;
}
}
}
byte Set(byte& Set, int Up, int Low, int Step, long Timer, byte Verso){
int step_size;
int ControllaPulsante;
delay(35);
if(Verso==1){
if(Set<Low)Set=Low;
if(Set>=Up)Set=Up;
ControllaPulsante=digitalRead(Button_up);
}
if(Verso==2){
if(Set>Up)Set=Up;
if(Set<=Low)Set=Low;
ControllaPulsante=digitalRead(Button_dn);
}
if(ControllaPulsante==0 && Verso!=0){
if(((millis()-Timer)/1000)>=4)step_size=(Step*10);
else{
if(((millis()-Timer)/1000)>=2)step_size=(Step*5);
else step_size=Step;
}
if(Verso==1){
if (Set+step_size>Up)Set=Up;
else Set+=step_size;
}else if(Verso==2){
if (Set-step_size<Low)Set=Low;
else Set-=step_size;
}
}
}