/
production_version.ino
382 lines (312 loc) · 12 KB
/
production_version.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*************************************************************************************
(cc) Jose Berengueres 4-8th Feb 2015, Dubai
(LCD sample code by Mark Bramwell, July 2010)
This is an Arduino based Ollie box implmentation used for regata starts
Components:
DF ROBOT LCD PANEL, 2 x RELAY Module v3.2, 1 x Arduino
connect the relay of the horn to D2 of LCD shield. This relay drives aircompressor (12VDC battery)
connect the relay that controls buzzer/beeper to D11.
**************************************************************************************/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define NUM_SEQ 4
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
#define RELAY_HORN 11 // horn relay
#define RELAY_BEEP 2 // beeper
#define STD_DELAY 300
#define SHORT_BEEP_LENGTH 500
#define WARNING_BEEP 0
#define SHORT_HORN 1
#define LONG_HORN 2
#define SUPER_LONG_HORN 3
bool toggle = true;
bool my_start = false;
unsigned long len_of_note[] = {500,400,800,1500}; // in ms
int prev_s;
int t;
int prev_mode = 5;
int mode = 5;
long start;
long ctdwn;
long sound_start;
unsigned long *sch;
int *h_or_b;
int index;
// warning long buzz (sb)= 0, short horn (sh) = 1, long horn (lh) =2 extralong horn 3
// Short seq countdown // 10lb 5sh 5blank 3lh
unsigned long sch_3[] = { 0, 10,20,30,40, 50,
100,
190, 200,
280,290,300,
1*600, 600 +10, 600+20, 600+30, 600+40, 600+50,
900-15-20, 900-15-10, 900-15, 900,
2*600-15, 2*600, 2*600+10, 2*600+20, 2*600+30, 2*600+40, 2*600+50,
3*600-30, 3*600-15, 3*600, 3*600+60, 3*600+70,3*600+80,3*600+90, 3*600+100,3*600+110, 3*600+120, 3*600+130, 3*600+140, 3*600+150, 3*600+160,3*600+170, 3*600+180, 3*600+190, 3*600+200 };
int h_or_b3[] ={
3, 1,1,1,1,1,
1,
1,1,
1,1,1,
2, 0,0,0,0,0,
1,1,1,2,
2,2,0,0,0,0,0,
2,2,2, 1,1,1,1,1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int index_3 = 6 + 6+ 6+ 4 + 7+ 18-1;
int ctdwn_3 = 205; // 3* 60 +39;
//************************************* FIVE MIN SEQ ********************************
unsigned long sch_5[] = { 0, 10, 20,30,40,50,
1*600, 1*600+10, 1*600+20, 1*600+30,1*600+40,1*600+50,
4*600, 4*600+10, 4*600+20, 4*600+30,4*600+40,4*600+50,
5*600,5*600+10,5*600+20,5*600+30,5*600+40,5*600+50, 5*600+60, 5*600+70,5*600+80,5*600+90,5*600+100,5*600+110, 5*600+120, 5*600+130, 5*600+140, 5*600+150, 5*600+160,5*600+170, 5*600+180, 5*600+190, 5*600+200 };
int h_or_b5[] = { 3, 0,0,0,0,0,
2, 0,0,0,0,0,
2,0,0,0,0,0,
2,0, 0, 0, 0, 0,1,1,1,1,1,0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int index_5 = 28+6+5-1; //
int ctdwn_5 = 5*60 + 25; // 9; //
//************************************* DOSC x1********************************
unsigned long sch_5british[] = { 0, 10, 20, 30, 40,50,
1*600, 1*600+10, 1*600+20, 1*600+30, 1*600+40,1*600+50,
4*600, 4*600+10, 4*600+20, 4*600+30, 4*600+40,4*600+50,
5*600,5*600+10,5*600+20, 5*600+30,5*600+40,5*600+50 };
int h_or_b5british[] = { 3, 0,0,0,0,0,
2, 0,0,0,0,0,
2, 0,0,0,0,0,
2, 0,0,0,0,0 };
int index_5british = 4*6-1 ; //
int ctdwn_5british = 5*60 + 8; //
//************************************* DOSC ROLLING x3 ********************************
unsigned long sch__3[] = { 0, 10, 20, 30, 40, 50,
1*600, 1*600+10, 1*600+20, 1*600+30, 1*600+40,1*600+50,
4*600, 4*600+10, 4*600+20, 4*600+30, 4*600+40,4*600+50,
5*600,5*600+10,5*600+20, 5*600+30,5*600+40,5*600+50,
6*600, 6*600+10, 6*600+20, 6*600+30, 6*600+40,6*600+50,
9*600, 9*600+10, 9*600+20, 9*600+30, 9*600+40,9*600+50,
10*600, 10*600+10, 10*600+20, 10*600+30, 10*600+40,10*600+50,
11*600, 11*600+10, 11*600+20, 11*600+30, 11*600+40,11*600+50,
14*600, 14*600+10, 14*600+20, 14*600+30, 14*600+40,14*600+50,
15*600, 15*600+10, 15*600+20, 15*600+30, 15*600+40,15*600+50
};
int h_or_b__3[] = {
3, 0,0,0,0,0,
2, 0,0,0,0,0,
2, 0,0,0,0,0,
3, 0,0,0,0,0,
2, 0,0,0,0,0,
2, 0,0,0,0,0,
3, 0,0,0,0,0,
2, 0,0,0,0,0,
2, 0,0,0,0,0,
2, 0,0,0,0,0 };
int index__3 = 10*6-1 ; //
int ctdwn__3 = 15*60 + 7; //
bool sound_on = false;
int read_LCD_buttons(){ // read the buttons
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
// We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in > 1000) return btnNONE;
// For V1.1 use this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
// For V1.0 comment the other threshold and use the one below:
/*
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
*/
return btnNONE; // when all others fail, return this.
}
// utility to print on LCD
void lcd_w(char a[16],char b[16]) {
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(a);
delay(STD_DELAY);
delay(STD_DELAY);
lcd.setCursor(0,1);
lcd.print(b);
delay(STD_DELAY);
delay(STD_DELAY);
}
void mymenu(){
lcd_w("BY CHRIS LABORDE"," & J BERENGUERES");
lcd_w("SELECT 5 OR 3 ","MINUTE SEQUENCE ");
}
/*
void vibrate(int n,int b, int c) {
for(int i=0;i<n;i++){
digitalWrite(RELAY_PIN, HIGH);
delay(b);
digitalWrite(RELAY_PIN, LOW);
delay(c);
}
}
*/
void setup(){
t =0;
Serial.begin(9600);
Serial.println("hello");
pinMode(RELAY_HORN, OUTPUT);
pinMode(RELAY_BEEP, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(0,0);
mymenu();
lcd.setCursor(0,1);
lcd.print("00:00 ");
}
void activate_sound(int a) {
// check what instrument to sound
int what_beep = RELAY_HORN;
if (a==WARNING_BEEP) { what_beep = RELAY_BEEP;}
digitalWrite(what_beep, HIGH);
sound_start = millis();
lcd.setCursor(7,1);
if (a==WARNING_BEEP) {
lcd.print("B");
}else{
lcd.print("H");
}
}
void de_activate_sound(int a) {
int what_beep = RELAY_HORN;
if (a==WARNING_BEEP) { what_beep = RELAY_BEEP;}
digitalWrite(what_beep, LOW);
lcd.setCursor(7,1);
lcd.print(" ");
}
void horn_or_beep(long s){
if (sound_on) {
if ( ((millis()-sound_start) > len_of_note[h_or_b[index]] ) ) {
de_activate_sound(h_or_b[index]);
sound_on = false;
index = index - 1;
}
}else{
unsigned long v = (sch[index]*100);
//Serial.println("long v = (long) (sch[index]*1000);");
//Serial.println(index);
//Serial.println(s);
//Serial.println(v);
if ( s < v +1000 ) { //if ( s < v + 500 ) {
activate_sound(h_or_b[index]);
sound_on = true;
}
}
}
void diplay_timer(long s){
if (s>-1){
int ss = (s/1000) %60;
int m = (s/1000)/60;
int s_pos = 3;
if (ss<10)
{ s_pos = s_pos +1;
lcd.setCursor(3,1);
lcd.print("0");
}
lcd.setCursor(1,1);
lcd.print(m);
lcd.setCursor(2,1);
lcd.print(":");
lcd.setCursor(s_pos,1);
lcd.print(ss);
}else{
lcd.setCursor(7,1);
lcd.print("START!");
digitalWrite(RELAY_HORN, LOW);
}
}
void loop(){
long s = millis()-start ;
if ( my_start ) {
long d = ctdwn*1000 - s ;
horn_or_beep( d );
diplay_timer( d );
}
lcd_key = read_LCD_buttons(); // read the buttons
delay(50);
switch (lcd_key){ // depending on which button was pushed, we perform an action
case btnLEFT:{
my_start = !my_start;
if (my_start) {
if (t==0){
lcd_w(" ...STARTING... ","DUBAI JASC 1x5 min ");
ctdwn = ctdwn_5 ;
sch = sch_5;
h_or_b = h_or_b5;
index = index_5;
}
if(t==1){
lcd_w(" ...STARTING... ","DUBAI JASC 1x3 min ");
ctdwn = ctdwn_3;
sch = sch_3;
h_or_b = h_or_b3;
index = index_3;
}
if (t==2) {
lcd_w(" ...STARTING... ","DOSC 1x5 min");
ctdwn = ctdwn_5british;
sch = sch_5british;
h_or_b = h_or_b5british;
index = index_5british;
}
if (t==3) {
lcd_w(" ...STARTING... ","DOSC ROLLING 3x5");
ctdwn = ctdwn__3;
sch = sch__3;
h_or_b = h_or_b__3;
index = index__3;
}
lcd.setCursor(0,1);
lcd.print("00:00 ");
sound_on = false;
start = millis();
break;
}else{
// stop
digitalWrite(RELAY_HORN, LOW);
digitalWrite(RELAY_BEEP, LOW);
lcd.setCursor(0,0);
lcd.print("SEQ. CANCELLED ");
my_start = false;
}
delay(400);
break;
}
case btnSELECT:{
if (!my_start) {
t = t + 1;
if (t>(NUM_SEQ-1)) {t= 0;}
lcd.setCursor(0,0);
if ( t == 0 ) { lcd.print("JASC 1x5min "); }
if ( t == 1 ) { lcd.print("JASC 1x3min "); }
if ( t == 2 ) { lcd.print("DOSC 1x5min "); }
if ( t == 3 ) { lcd.print("DOSC ROLLING 3x5"); }
lcd.setCursor(0,1);
lcd.print(" ");
delay(400);
break;
}
}
case btnNONE:{
break;
}
}
}