-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu_shield_timer_stepper.ino
324 lines (256 loc) · 8.73 KB
/
menu_shield_timer_stepper.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
#define version "V 1.00" //15/11/2021
//menu_shield_timer_stepper.ino
//https://www.usinages.com/threads/reglage-vitesse-moteur-p-a-p-avec-minuterie.148831/post-1876324
// commande d'un moteur pas à pas avec temporisation
// paramétrage par menu déroulant
// Shield Arduino LCD Keypad
// LCD en port // 4 bits
// Clavier par résistances sur port analogique A0
// Les valeurs de test du clavier sont à modifier dans clavier.h en fonction des résistances implantées sur le shield
// La LIB MD_UISwitch est codée avec des temps courts pour la gestion des touches
// Cela peut être modifié dans le code de la LIB
/*
C:\Users\XXXXXX\Documents\Arduino\libraries\MD_UISwitch\src
MD_UISwitch.h
static const uint16_t KEY_PRESS_TIME = 150; ///< Default key press time in milliseconds
static const uint16_t KEY_DPRESS_TIME = 250; ///< Default double press time between presses in milliseconds
static const uint16_t KEY_LONGPRESS_TIME = 600; ///< Default long press detection time in milliseconds
static const uint16_t KEY_REPEAT_TIME = 300; ///< Default time between repeats in in milliseconds
static const uint8_t KEY_ACTIVE_STATE = LOW; ///< Default key is active low - transition high to low detection
Pour que ce soit plus confortable rallonger les tempos comme ceci:
static const uint16_t KEY_PRESS_TIME = 250; ///< Default key press time in milliseconds
static const uint16_t KEY_DPRESS_TIME = 350; ///< Default double press time between presses in milliseconds
static const uint16_t KEY_LONGPRESS_TIME = 700; ///< Default long press detection time in milliseconds
static const uint16_t KEY_REPEAT_TIME = 400; ///< Default time between repeats in in milliseconds
*/
// Saisie améliorée par choix de l'action avec < > ( valeur 0 ,1 ,10 ,100 ,1000 )
// Stepper Pin : Step 3 Dir 2
// Version Speedjf37 à partir du projet:
//https://giltesa.com/2016/10/24/menu-submenus-shield-lcd-arduino
/**
* Name: Arduino - Menu for Shield LCD
* Autor: Alberto Gil Tesa
* Web: http://giltesa.com
* License: CC BY-NC-SA 3.0
* Date: 2016/12/10
*
* Arduino Uno, Pinout:
* _______________
* | USB |
* |13 12|
* |3V3 11|
* |AREF 10|
* APAD |A0 9| LCD
* |A1 8| LCD
* |A2 7| LCD
* |A3 6| LCD
* |A4 5| LCD
* |A5 4| LCD
* | 3/SCL|
* | 2/SDA|
* |5V GND|
* |RST RST|
* |GND 1/INT2/RX|
* |VIN 0/INT3/TX|
* |MISO SS|
* |SCK MOSI|
* |_______________|
*
*/
//Variables Globales
int TimerState = 0;
int TimerState_old=-1;
int aff_TimerState =-1;
int aff_VitesseMot = -1;
int VitesseMot = 0;
int VitesseMot_Old = -1;
int Count_Sec=0;
int aff_sec = -1;
int aff_min = -1;
int aff_heu = -1;
int new_sec = 0;
int new_min = 0;
int new_heu = 0;
int RUN =0;
// Pour alleger le code il est divisé par LIB
void Mot_1Tr(void);
#include "Lcd.h"
char Txt_Run[4]={
'|',
'/',
'-',
C_BackSlash //customBackslash voir Lcd.h
};
#include "Eeprom.h"
#include "Clavier.h"
#include "Menu.h"
#include "StepperIndexer.h"
/**
*
*/
void setup()
{
Serial.begin(57600);
// Charge la configuration de l' EEPROM sinon config par défaut:
readConfiguration();
SetupLcd();
SetupClavier();
SetupStepperIndexer();
// affiche le nom du projet en cours pendant 2 secondes:
lcd.setCursor(0,0); lcd.print("Menu Shield LCD ");
lcd.setCursor(0,1); lcd.print("Tim + Step ");
lcd.print(version);
Serial.println();
Serial.print("Timer + Stepper ");
Serial.println(version);
Serial.println();
delay(2000);
set_menu_exit(); // Force l'état MENU_NO et affichage principal
}
#define MENU_NO_print
void loop()
{
char buffercar[17];
tNow = millis();
T_Menu();
if (Menu_Rang == MENU_NO ) // Si pas de menu en cours
{ // affichage principal
if (aff_TimerState == -1)
{
//AFFICHAGE GLOBAL
//#ifdef MENU_NO_print
Serial.println(" AFFICHAGE GLOBAL ");
//#endif
//lcd.clear(); // deplacé dans set_menu_exit
lcd.setCursor(2,0);
if (TimerState == 0)
lcd.print("S:");
if (TimerState == 1)
lcd.print("R:");
if (TimerState == 2)
lcd.print("P:");
// AFF TIMER
sprintf(buffercar,"T1:%02dh%02dm%02ds",Count_Sec/3600 %24 ,Count_Sec/60 %60,Count_Sec %60);
lcd.print(buffercar);
#ifdef MENU_NO_print
Serial.print(" AFF TIMER :");
Serial.println(buffercar);
#endif
lcd.setCursor(0,2);
lcd.print("Vit: ");
lcd.setCursor(5,1);
lcd.print(" 0 ");
//lcd.setCursor(5,1);
//lcd.print((VitesseMot/memory.d.mot_pas)*60);//tr/mn
lcd.setCursor(11,1);
lcd.print("Tr/mn");
}
if(TimerState_old != TimerState)
{
#ifdef MENU_NO_print
Serial.print("TimerState : ");
Serial.println(TimerState);
#endif
if ( (TimerState == 1)&&(TimerState_old == 0))//start
{
#ifdef MENU_NO_print
Serial.println("Start Timer :");
#endif
Count_Sec = (memory.d.Timer1_heu * 3600) + (memory.d.Timer1_min * 60) + memory.d.Timer1_sec ;
MyStepper.SetAccel(memory.d.mot_accel);
VitesseMot=memory.d.mot_vit;
MyStepper.SetSpeed(VitesseMot);
}
if( (TimerState ==1)&&(TimerState_old ==2 )) //fin Pause Restart
{
MyStepper.SetAccel(memory.d.mot_accel);
VitesseMot=memory.d.mot_vit;
MyStepper.SetSpeed(VitesseMot);
}
if (( (TimerState == 0)&&(TimerState_old != 0))||( (TimerState ==2)&&(TimerState_old ==1)) )//stop ou pause
{
//ARRET du moteur
#ifdef MENU_NO_print
Serial.println("Stop Timer :");
#endif
VitesseMot =0;
MyStepper.SetSpeed(VitesseMot);
}
TimerState_old = TimerState;
}//end if (TimerState_old!=TimerState)
// Traitement si temps ecoulé 1 seconde:
if ( tNow - tPrevious >= 1000 )
{
tPrevious = tNow;
RUN++;
if (RUN>3)
RUN=0;
lcd.setCursor(0,0);
lcd.print(Txt_Run[RUN]);
if (TimerState == 1)
if (Count_Sec>0)
{
Count_Sec --;
if (Count_Sec == 0)// ARRET du moteur
{
// end timer Stop Stepper
VitesseMot = 0;
MyStepper.SetSpeed(VitesseMot);
}
new_sec=Count_Sec %60;
new_min=Count_Sec/60 %60;
new_heu=Count_Sec/3600 %24;
}
aff_TimerState = TimerState ;
}// end t 1s
// AFFICHAGE sur changement de valeur
if (TimerState != aff_TimerState)
{
lcd.setCursor(2,0);
if (TimerState == 0)
lcd.print("S:");
if (TimerState == 1)
lcd.print("R:");
if (TimerState == 2)
lcd.print("P:");
aff_TimerState = TimerState ;
}
if ( new_heu != aff_heu)
{
aff_heu = new_heu;
lcd.setCursor(7,0);
sprintf(buffercar,"%02d", new_heu);
lcd.print(buffercar);
Serial.print("Aff heu :");
Serial.println(buffercar);
}
if ( new_min != aff_min)
{
aff_min = new_min;
lcd.setCursor(10,0);
sprintf(buffercar,"%02d", new_min);
lcd.print(buffercar);
Serial.print("Aff min :");
Serial.println(buffercar);
}
if ( new_sec != aff_sec)
{
aff_sec = new_sec;
lcd.setCursor(13,0);
sprintf(buffercar,"%02d", new_sec);
lcd.print(buffercar);
Serial.print("Aff sec :");
Serial.println(buffercar);
}
if (VitesseMot != aff_VitesseMot)
{
lcd.setCursor(5,1);
lcd.print(" ");
lcd.setCursor(5,1);
lcd.print((VitesseMot/memory.d.mot_pas)*60);//tr/mn memory.d.mot_vit step/s
//Serial.print("VitesseMot : ");
//Serial.println(VitesseMot);
aff_VitesseMot = VitesseMot;
}
}// end aff no_menu
} // end loop