-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFinaleCode.ino
313 lines (212 loc) · 5.43 KB
/
FinaleCode.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// Proximity sensor pin define
#define sensorPin 12
// Temperature sensor pin defines
#define SDA_PORT PORTD
#define SDA_PIN 6
#define SCL_PORT PORTD
#define SCL_PIN 5
//Motor Driver pin defines
#define RedA1 2
#define RedB1 4
#define Enable 3
//how many times to mesure the beer temperature
#define PROBING_TIMES 8
//min and max temp for the perfect beer
//info from our survey
#define TEMP_LOW_LEVEL 5
#define TEMP_HIGH_LEVEL 11
//our custom char defines
#define DEGREE_SYM 0
#define BEER_1 1
#define BEER_2 2
//Motor parameters
#define RIGHT_SIDE_SPEED 64
#define RIGHT_SIDE_DURATION 3000 //miliseconds
#define LEFT_SIDE_SPEED 64
#define LEFT_SIDE_DURATION 3000 //ms
#include "Wire.h"
//for LCD
#include "LiquidCrystal_I2C.h"
//for temperature sensor
#include "MLX90615.h"
//creating an object to control the lcd
LiquidCrystal_I2C lcd(0x3F,16,2); //setting Arduino I2C address and dimensions 2 x 16
//creating an object to control the temperature sensor
MLX90615 TempSensor;
//some useful Print functions
void PrintStr(const String& s){
uint8_t len = s.length();
for(uint8_t i = 0 ; i <len ; ++i)
lcd.print(s[i]);
}
void PrintFloat(const float& pFloat){
String num(pFloat);
PrintStr(num);
}
void PrintNewLine(){
lcd.setCursor(0,1);
}
//prints new line with indentation
void PrintNewLineIndt(){
lcd.setCursor(1,4);
}
//Prints our custom 'beer' char
void PrintBeerSym(){
lcd.write(BEER_1);
lcd.write(BEER_2);
}
//not used
/*
void openContainer()
{
lcd.setCursor(0, 1);
PrintStr("Shit son");
}
*/
//motor control functions
inline void rotateRight(int duration, int power){
digitalWrite(RedA1, HIGH);
digitalWrite(RedB1, LOW);
analogWrite(Enable, power);
delay(duration);
}
inline void rotateLeft(int duration, int power){
digitalWrite(RedA1, LOW);
digitalWrite(RedB1, HIGH);
analogWrite(Enable, power);
delay(duration);
}
inline void stopRotation(){
digitalWrite(RedA1, LOW);
digitalWrite(RedB1, LOW);
}
//commands for the motor to open the beer
void openBeer(){
rotateLeft(LEFT_SIDE_DURATION,LEFT_SIDE_SPEED);
stopRotation();
delay(1000);
rotateRight(RIGHT_SIDE_DURATION,RIGHT_SIDE_SPEED);
stopRotation();
}
//mesures the beer temperature
//and returns the average
float getAverageTemp(uint8_t samples){
float avrgTemp = 0.0;
for(uint8_t i = 0; i < samples; ++i)
avrgTemp += TempSensor.getObjTemperature(MLX90615_OBJECT_TEMPERATURE);
return avrgTemp /= samples;
}
void setup_lcd(){
lcd.init();
delay(100);
lcd.clear();
delay(100);
lcd.setBacklight(0);
delay(100);
//arrays that defines our custom chars
uint8_t letter[] = { 14, 17, 17, 17, 14, 0, 0, 0 };
uint8_t beer1[] = { 4, 6, 23, 23, 23, 15, 7, 31 };
uint8_t beer2[] = { 4, 12, 28, 28, 28, 28, 28, 31 };
lcd.load_custom_character(DEGREE_SYM, letter);
lcd.load_custom_character(BEER_1, beer1);
lcd.load_custom_character(BEER_2, beer2);
lcd.clear();
}
void setup(){
TempSensor.init();
setup_lcd();
pinMode(sensorPin, INPUT);
pinMode(RedA1,OUTPUT);
pinMode(RedB1, OUTPUT);
pinMode(Enable, OUTPUT);
}
bool FirstTruningOn = true;
void loop(){
//checks if this is the first usage of the bot
//after switching on
if(FirstTruningOn){
PrintStr("starting the");
lcd.setCursor(1,4);
PrintStr("BeerBoot...");
delay(4000);
FirstTruningOn = false;
}
lcd.clear();
PrintStr("Please put a");
lcd.setCursor(1,4);
PrintBeerSym();
PrintStr("...");
uint8_t sensorState = HIGH; // there isn't an object
//trying to catch an object every second
while(sensorState == HIGH){
sensorState = digitalRead(sensorPin);// returns LOW if there is an object
delay(1000);
}
//checking if the object is there for 3 seconds
for(int i=0;i <3 ;i++){
sensorState = digitalRead(sensorPin);
delay(1000);
}
lcd.clear();
if(sensorState == LOW)
{
PrintStr("A ");
PrintBeerSym();
PrintStr(" has been");
PrintNewLineIndt();
PrintStr("detected!");
delay(4000);
lcd.clear();
PrintStr("Measuring the ");
PrintBeerSym();
PrintNewLineIndt();
PrintStr("temperature...");
delay(5000);
float avrgTemp = getAverageTemp(PROBING_TIMES);
if(avrgTemp > TEMP_LOW_LEVEL && avrgTemp < TEMP_HIGH_LEVEL){
lcd.clear();
PrintStr("The ");
PrintBeerSym();
PrintStr(" is ");
PrintFloat(avrgTemp);
PrintStr("C");
lcd.write(DEGREE_SYM);
delay(5000);
lcd.clear();
PrintStr("Proceeding to");
PrintNewLine();
PrintStr("open the ");
lcd.write(BEER_1);
lcd.write(BEER_2);
PrintStr(" ...");
openBeer();
delay(5000);
lcd.clear();
PrintStr("ENJOY YOUR BEER!!!");
delay(5000);
}
else{
lcd.clear();
PrintStr("the ");
PrintBeerSym();
PrintStr(" temp is");
PrintNewLine();
PrintStr("NOT acceptable!");
delay(5000);
lcd.clear();
PrintStr("opening is up");
PrintNewLine(); //new line
PrintStr("to your decision..") ;
}
delay(5000);
lcd.clear();
PrintStr("HACKED BY TEAM");
PrintNewLine();
PrintStr("BEEROVERLORDS");
//waiting the beer to be removed
while(sensorState == LOW){
delay(1000);
sensorState = digitalRead(sensorPin);
}
}
}