-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUTFT.ino
680 lines (564 loc) · 19 KB
/
UTFT.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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/********************
Sept. 2014 ~ Oct 2016 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
menu with UTFT (tested on arduino due)
output: 3.2″ TFT LCD Module Display 240X320
input: Serial + Touch Panel
www.r-site.net
UTFT library from:
http://www.rinkydinkelectronics.com/library.php?id=51
http://www.rinkydinkelectronics.com/library.php?id=92
Note: I was unable to build for esp8266 - neu-rah
***/
/***
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduino Duemilanove: 512 B EEPROM storage.
- Arduino Uno: 1 kB EEPROM storage.
- Arduino Mega: 4 kB EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
#include <Arduino.h>
#include <menu.h>
#include <menuIO/utftOut.h>
//#include <menuIO/urtouchIn.h>
#include <TimerOne.h>
#include <ClickEncoder.h>
#include <menuIO/clickEncoderIn.h>
#include <menuIO/keyIn.h>
#include <menuIO/serialOut.h>
#include <menuIO/serialIn.h>
#include <menuIO/chainStream.h>
#include <plugin/userMenu.h>
#include <plugin/cancelField.h>
#include <plugin/barField.h>
#include <FastPID.h> // Include PID Library
#include <AccelStepper.h>
#include <EEPROM.h>
#include <Adafruit_ADS1X15.h>
using namespace Menu;
UTFT tft(SSD1289 ,38,39,40,41);
//extern uint8_t SmallFont[];
extern uint8_t SmallFont[];
extern uint8_t SevenSegmentFull[];
extern uint8_t DotMatrix_M_Slash[];
extern uint8_t BigFont[];
//extern uint8_t SevenSegNumFont[];
#define LEDPIN 13
#define PLASMA_INPUT_PIN A0
#define STEP_PIN 8 // Direction
#define DIR_PIN 9 // Step
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN, DIR_PIN);
Adafruit_ADS1115 ads;
//Define Variables
double Input = 0;
float targetInput;
float gap;
float scale;
long threshold=74000;
long currentGap;
uint32_t oldDelay;
uint32_t arcStabilizeDelay;
long SetPoint = 6335;
long CalibrationOffset = 0;
//Specify the links and initial tuning parameters
float aggKp = 0.175, aggKi = 0.1, aggKd = 0.1;
float Kp = 0.075, Ki = 0.01, Kd = 0.01;
float Hz = 8;
int output_bits = 16;
bool output_signed = true;
bool alreadySetColor = false;
FastPID THCPID(Kp, Ki, Kd, Hz, output_bits, output_signed);
////////////////////////////////////////////////////////////////////////////
long RPMD=1000;
int RPMvfd;
int minimo=10;
int maximo=80;
int automanual=0;
int hsensor=90;
int holgura=20;
int porcentaje=0;
int ledCtrl=LOW;
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int Tiempo =0;
int tempInicioCiclo =0;
int temperaturaResMax =0;
int Tiempo_cal =0;
int tempInicioCiclo_cal =0;
int temperaturaResMax_cal =0;
int buff_time;
String target1;
String string_buff;
constexpr int dataSz=6; //cantidad de recetas, maximo 23...0-22
constexpr int nameSz=11;// longitud de nombre de receta
char char_buff[nameSz+1];
char idxchar[dataSz];
int id;
int id2;
int idx_update;
int number;
int test=0;
int tempAct;
int tempActual;
int temp_Recamara;
int temp_Resistencia ;
//int temperaturaResMax2=300;
//int temperaturaResMax3=200;
int temperaturaResMax2=240;
int temperaturaResMax3=240;
int TAPA_CERRADA=0;
int CALENTADO=0;
int CALIBRAR=0;
int tiempo_minutos=0;
int tiempo_segundos=0;
int8_t offset1 =0;
int8_t offset2 =0;
int pass=1234;
int button1_State = 0, button2_State = 0, button3_State = 0, button4_State = 0;
int prestate =0;
unsigned long lastMillis = 0;
bool iniciar = false;
///////////////////////////////////////////////////////////////////////////////////////
//movement
long steps_per_mm = 200;
float pos = 0;
float adjpos = 0;
long minPos = -(40 * steps_per_mm);
long maxPos = (40 * steps_per_mm);
long moveAmt = 0;
uint8_t output = 0;
// Encoder /////////////////////////////////////
#define encA 45
#define encB 47
//this encoder has a button here
#define encBtn 49
ClickEncoder clickEncoder(encA,encB,encBtn,2);
ClickEncoderStream encStream(clickEncoder,1);
MENU_INPUTS(in,&encStream);
void timerIsr() {clickEncoder.service();}
//some user data record type to be edited by the menu
struct Data {
char name[nameSz+1]= "<vacio> ";
};
//THE DATA <-----------------------------------------
Data myTargets[dataSz];//our data
Data target;
//characters allowed on name field
const char* constMEM alphaNum MEMMODE=" 0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,\\|!\"#$%&/()=?~*^+-{}[]€";
const char* constMEM alphaNumMask[] MEMMODE={alphaNum};
char* constMEM hexDigit MEMMODE="0123456789";
char* constMEM hexNr[] MEMMODE={hexDigit,hexDigit,hexDigit,hexDigit};
char buf1[]="****";
result datos2() {EEPROM.write(1, offset1);return proceed;}
result datos3() {EEPROM.write(3, offset2);return proceed;}
// result datos4() {return proceed;}
// result datos5() {return proceed;}
result dataSize(){EEPROM.write(0, test);return proceed;}
result datUpdate(){/*update_data();*/ return proceed;}
result saveoffset(){ return proceed;}
result callEvent() {
Serial.print("call event: ");
// lcd.clear();
CALIBRAR=1;
//load_data();
//delay(1200);
return proceed;
}
//a function to save the edited data record
result saveTarget(eventMask e,navNode& nav) {
trace(MENU_DEBUG_OUT<<"saveTarget"<<endl);
navNode& nn=nav.root->path[nav.root->level-1];
idx_t n=nn.sel;//get selection of previous level
myTargets[n]=target;
id=n;
//save_data();
return quit;
}
MENU(subMenu1,"-Configurar",datUpdate,enterEvent,noStyle
,FIELD(Tiempo,"-SetPoint"," Volt",0,500,10,1,datos1,exitEvent,wrapStyle)
,FIELD(tempInicioCiclo,"-ArcDelay","msec",0,400,10,1,datos2,exitEvent,wrapStyle)
,FIELD(temperaturaResMax,"-Offset"," Volt",0,400,10,1,datos3,exitEvent,wrapStyle)
,EXIT("<Regresar")
);
MENU(targetEdit,"Editar receta",doNothing,noEvent,wrapStyle
,EDIT("Name",target.name,alphaNumMask,doNothing,noEvent,noStyle)
,SUBMENU(subMenu1)
,OP("-Salvar",saveTarget,enterEvent)
,EXIT("<Regresar")
);
//handling the user menu selection
//this will copy the selected recotd into the temp var
result targetEvent(eventMask e,navNode& nav);
struct TargetMenu:UserMenu{
using UserMenu::UserMenu;
Used printItem(menuOut& out, int idx,int len) override {
return len?out.printText(myTargets[idx].name,len):0;
}
};
//build the user menu object, optionally giving a sub menu
#ifdef MENU_USERAM
//for non-AVR devices or when MENU_USERAM is defined at compiler level
//TargetMenu targetsMenu("Targets",dataSz,"<Back",targetEdit,targetEvent,enterEvent);
TargetMenu targetsMenu("-Recetas",dataSz,targetEdit,targetEvent,enterEvent);//no exit option
#else
//menu allocation compatible with AVR flash ---------------------------------
constMEM char targetsMenuTitle[] MEMMODE="-Recetas";
constMEM menuNodeShadowRaw targetsMenuInfoRaw MEMMODE={
(callback)targetEvent,
(systemStyles)(_menuData|_canNav),
targetsMenuTitle,
enterEvent,
wrapStyle,
dataSz,
NULL
};
constMEM menuNodeShadow& targetsMenuInfo=*(menuNodeShadow*)&targetsMenuInfoRaw;
TargetMenu targetsMenu(targetsMenuInfo,targetEdit,"<Regresar");//no exit option
#endif
//customizing a prompt look!
//by extending the prompt class
class recetaPrompt:public prompt {
public:
unsigned int t=0;
unsigned int last=0;
recetaPrompt(constMEM promptShadow& p):prompt(p) {}
Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t) override {
last=t;
// return out.printRaw(myTargets[2].name,len);
return out.printText((myTargets[test].name),len);
// return len?out.printText(myTargets[idx].name,len):0;
// return out.printRaw(F("special prompt!"),len);;
}
virtual bool changed(const navNode &nav,const menuOut& out,bool sub=true) {
t=millis()/1000;
return last!=t;
}
// virtual void clearChanged(const navNode &nav,const menuOut& out,bool sub) {
// dirty = false;
// t=millis()/1000;
// if (last!=t) {
// dirty = true;
// }
// }
};
MENU(subMenu,"-Opciones",showEvent,exitEvent,noStyle
,EDIT("-Pass",buf1,hexNr,datos1,exitEvent,wrapStyle)
,FIELD(offset1,"-Offset1","\xDF C",-200,200,1,1,datos2,exitEvent,wrapStyle)
,FIELD(offset2,"-Offset2","\xDF C",-200,200,1,1,datos3,exitEvent,wrapStyle)
,FIELD(Tiempo_cal,"-Tiempo"," sec",0,500,10,1,datos6,exitEvent,wrapStyle)
,FIELD(tempInicioCiclo_cal,"-Tempinic","\xDF C",0,400,10,1,datos4,exitEvent,wrapStyle)
,FIELD(temperaturaResMax_cal,"-TempRes","\xDF C",0,400,10,1,datos5,exitEvent,wrapStyle)
,OP("-Calibrar",callEvent,enterEvent)
,OP("-Salvar",saveoffset,enterEvent)
,EXIT("<Regresar")
);
MENU(mainMenu,"Selec. Metales",doNothing,noEvent,wrapStyle
,FIELD(test,"Num. Metal","",0,5,1,0,dataSize,exitEvent,noStyle)
,altOP(recetaPrompt,"",processing,enterEvent)
,OBJ(targetsMenu)//attach the array edit menu on a macri build nenu
,SUBMENU(subMenu)
// ,SUBMENU(subMenu2)
,EXIT("<Regresar")
);
result targetEvent(eventMask e,navNode& nav) {
trace(MENU_DEBUG_OUT<<"copy data to temp target:"<<(int)nav.target<<"\n");
if(nav.target==&targetsMenu)//only if we are on targetsMenu
target=myTargets[nav.sel];
id2=nav.sel; //id entrada receta
//you can store nav.sel for future reference
return proceed;
}
// define menu colors --------------------------------------------------------
// {{disabled normal,disabled selected},{enabled normal,enabled selected, enabled editing}}
//monochromatic color table
const colorDef<uint16_t> colors[6] MEMMODE={
{{VGA_BLACK,VGA_BLACK},{VGA_BLACK,VGA_BLUE,VGA_BLUE}},//bgColor
{{VGA_GRAY,VGA_GRAY},{VGA_WHITE,VGA_WHITE,VGA_RED}},//fgColor
{{VGA_WHITE,VGA_BLACK},{VGA_YELLOW,VGA_YELLOW,VGA_RED}},//valColor
{{VGA_WHITE,VGA_BLACK},{VGA_WHITE,VGA_YELLOW,VGA_YELLOW}},//unitColor
{{VGA_WHITE,VGA_GRAY},{VGA_BLACK,VGA_BLUE,VGA_GRAY}},//cursorColor
{{VGA_WHITE,VGA_YELLOW},{VGA_WHITE,VGA_BLACK,VGA_RED}},//titleColor
};
//PANELS(serial_panels,{0,0,40,10});//or use default
//serialOut outSerial(Serial);//,serial_panels);//the output device (just the serial port)
#define MAX_DEPTH 4
PANELS(gfx_panels,{0,0,16,12});
//PANELS(gfx_panels,{0,0,12,8},{13,0,12,8});
idx_t gfx_tops[MAX_DEPTH];
utftOut outGfx(tft,colors,gfx_tops,gfx_panels,16,16);//output device, latter set resolution from font measure
idx_t serialTops[MAX_DEPTH]={0};
serialOut outSerial(Serial,serialTops);
MENU_OUTLIST(out,&outGfx,&outSerial);
serialIn serial(Serial);
//extern navRoot nav;
//URTouch uTouch( 6, 5, 4, 3, 2);
//menuUTouch touchPanel(uTouch,nav,outGfx);
//serialIn serial(Serial);
//
//MENU_INPUTS(in,&touchPanel,&serial);
NAVROOT(nav,mainMenu,MAX_DEPTH,in,out);
//
//result alert(menuOut& o,idleEvent e) {
// if (e==idling) {
// o.setColor(fgColor);
// o.setCursor(0,0);
// o.print("alert test");
// o.setCursor(0,1);
// o.print("press [select]");
// o.setCursor(0,2);
// o.print("to continue...");
// }
// return proceed;
//}
//
//result doAlert(eventMask e, prompt &item) {
// nav.idleOn(alert);
// return proceed;
//}
//when menu is suspended
result idle(menuOut& o,idleEvent e) {
if (e==idling) {
drawHomeScreen();
}
return proceed;
}
result datos4() {return proceed;}
result datos5() {return proceed;}
result datos6() {return proceed;}
result processing(){CALIBRAR=0;/*load_data();*/nav.idleOn() ;return proceed;}
result showEvent(eventMask e) {
subMenu[1].enabled=disabledStatus;
subMenu[2].enabled=disabledStatus;
subMenu[6].enabled=disabledStatus;
CALIBRAR=0;
Serial.print("event: ");
Serial.println(e);
return proceed;
}
result datos1() {
String mypass(buf1);
int password = mypass.toInt();
if (password == pass) {
strncpy(buf1,"****",4);
subMenu[1].enabled=enabledStatus;
subMenu[2].enabled=enabledStatus;
subMenu[6].enabled=enabledStatus;
mainMenu[2].enabled=enabledStatus;
} return proceed;}
void setup() {
pinMode(LEDPIN,OUTPUT);
pinMode(encBtn,INPUT_PULLUP);
while(!Serial);
Serial.begin(9600);
Serial.println("menu 4.x UTFT + URTouch");Serial.flush();
ads.setGain(GAIN_ONE);
nav.idleTask=idle;//point a function to be used when menu is suspended
// mainMenu[1].enabled=disabledStatus;
nav.timeOut = 5;
//nav.showTitle=false;
nav.exit();
tft.InitLCD();
tft.setBrightness(4);
tft.clrScr();
for( number = 0; number < dataSz; number++) {
String texto = String(number) +"<vacio> ";
texto.toCharArray(char_buff, nameSz+1);
strncpy(myTargets[number].name,char_buff,nameSz+1);
// writeIntIntoEEPROM(356+(number*6), 0);EEPROM.commit();
// writeStringToEEPROM((number*(nameSz+1))+5,texto);
// EEPROM.commit();
Serial.println(String(number) +"<vacio> ");
//for( number = 356; number < 489; number++) {
// writeIntIntoEEPROM(number, 0);EEPROM.commit();
//
//}
}
for(idx_update = 0; idx_update < dataSz; idx_update++) {
string_buff = readStringFromEEPROM((idx_update*(nameSz+1))+5);
string_buff.toCharArray(char_buff, nameSz+1);
strncpy(myTargets[idx_update].name,char_buff,nameSz+1);
}
// uTouch.InitTouch();
// uTouch.setPrecision(PREC_MEDIUM);//LOW, MEDIUM, HI, EXTREME
tft.setFont(BigFont);
tft.setColor(0, 255, 0);
tft.setBackColor(0, 0, 0);
//outGfx.resX=tft.getFontXsize()+1;
//outGfx.resY=tft.getFontYsize()+1;
outGfx.println("Menu 4.x on UTFT");
Timer1.initialize(500);
Timer1.attachInterrupt(timerIsr);
//Setup Stepper Driver
stepper.setMaxSpeed(150000); //thru experimentation I found these values to work... Change for your setup.
stepper.setAcceleration(20000);
delay(1000);
tft.clrScr();
}
void loop() {
nav.poll();//this device only draws when needed
if (nav.sleepTask)// If the menu system is not active, draw the main screen
{
//sensorValue = analogRead(sensorPin);
Input = map(analogRead(PLASMA_INPUT_PIN), 0, 1023, 0, 25000) + CalibrationOffset; //reads plasma arc voltage and convert to millivolt
process(); //This is the main method of the application it calulates position and move steps if Input Voltage is over threshold.
report();
}
// digitalWrite(LEDPIN, ledCtrl);
// delay(100);//simulate a delay when other tasks are done
}
void process() //Calulates position and move steps
{
oldDelay = micros();
while (Input > (threshold + CalibrationOffset)) //Only move if cutting by checking for voltage above a threshold level
{
if (micros() - oldDelay >= arcStabilizeDelay) //wait for arc to stabilize tipically 100-300ms
{
Input = map(analogRead(PLASMA_INPUT_PIN), 0, 1023, 0, 25000) + CalibrationOffset; //get new plasma arc voltage and convert to millivolts
currentGap = abs(SetPoint - Input); //distance away from setpoint
if (currentGap < gap) {
THCPID.setCoefficients(Kp, Ki, Kd, Hz); //we're close to setpoint, use conservative tuning parameters
}
else {
THCPID.setCoefficients(aggKp, aggKi, aggKd, Hz); //we're far from setpoint, use aggressive tuning parameters
}
if (SetPoint > Input)
{
targetInput = Input - SetPoint + SetPoint;
output = THCPID.step(SetPoint, targetInput);
pos = pos + output;
// Serial.print("sp>in: ");
// Serial.println(output);
}
else
{
targetInput = SetPoint - Input + SetPoint;
output = THCPID.step(SetPoint, targetInput);
pos = pos - output;
// Serial.print("sp<in: ");
// Serial.println(output);
}
//Validate move is within range
if (pos >= maxPos) {
pos = maxPos;
}
if (pos <= minPos) {
pos = minPos;
}
Serial.print("pos: ");
Serial.println(pos);
//do move
stepper.moveTo(pos);
while (stepper.distanceToGo() != 0) {
stepper.run();
}
report(); //report plasma voltage and position
//format();
}
}
//after cut reset height
pos = 0;
//do move
stepper.moveTo(pos);
while (stepper.distanceToGo() != 0) {
stepper.run();
}
}
void report() {
tft.setFont(SevenSegmentFull);
tft.setColor(255, 0, 0);
tft.setBackColor(0, 0, 0);
// tft.printNumI(input,175, 85, 3,'0');
tft.printNumF(Input/1000,3, 145, 85,'.', 0,' ');
tft.setFont(DotMatrix_M_Slash);
tft.setColor(255, 255, 0);
tft.printNumF(pos/1000,3, 175, 52,'.', 7,' ');
tft.setFont(BigFont);
}
void drawHomeScreen() {
tft.setFont(SevenSegmentFull);
tft.setColor(0, 255, 0);
tft.setBackColor(0, 0, 0);
tft.printNumI(SetPoint,175, 140, 3,'0');
tft.setColor(100, 155, 203);
tft.fillRoundRect (10, 10, 60, 36);
tft.setColor(255, 255, 255);
tft.drawRoundRect (10, 10, 60, 36);
tft.drawRoundRect (10, 10, 60, 36);
tft.setFont(BigFont);
tft.setBackColor(100, 155, 203);
tft.print("<-", 18, 15);
tft.setBackColor(0, 0, 0);
tft.setFont(BigFont);
tft.print("THC Control", CENTER, 15);
tft.print("Divider:", 10, 101);
tft.print("Set point:", 10, 156);
tft.print("Position:", 10, 55);
tft.setColor(255, 0, 0);
tft.drawLine(0,45,319,45);
tft.setColor(255, 0, 0);
tft.drawLine(0,82,319,82);
tft.setColor(255, 0, 0);
tft.drawLine(0,137,319,137);
tft.setColor(255, 255, 255);
tft.drawRect(15, 198, 310, 228);
}
void update_data()
{
Tiempo = readIntFromEEPROM(356+(id2*2));
tempInicioCiclo = readIntFromEEPROM(401+(id2*2));
temperaturaResMax = readIntFromEEPROM(446+(id2*2));
}
void save_data()
{
for(int idx2 = 0; idx2 < dataSz; idx2++) {
if (idx2==id){target1 = String(target.name);
//EEPROM.write(idx2, buff_time);EEPROM.commit();
writeStringToEEPROM((idx2*(nameSz+1))+5, target1);
// Serial.println(idx2);}
delay(10);// break;
}
}
for(int dat1 = 0; dat1 < dataSz; dat1++) {
if (dat1==id2){
writeIntIntoEEPROM(356+(dat1*2), Tiempo);
delay(10);}}
for(int dat2 = 0; dat2 < dataSz; dat2++) {
if (dat2==id2){
writeIntIntoEEPROM(401+(dat2*2), tempInicioCiclo);
delay(10);}}
for(int dat3 = 0; dat3 < dataSz; dat3++) {
if (dat3==id2){
writeIntIntoEEPROM(446+(dat3*2), temperaturaResMax);
delay(10);}}
}
void writeIntIntoEEPROM(int address, int number)
{
EEPROM.write(address, number >> 8);
EEPROM.write(address + 1, number & 0xFF);
}
int readIntFromEEPROM(int address)
{
return (EEPROM.read(address) << 8) + EEPROM.read(address + 1);
}
void writeStringToEEPROM(int addrOffset, const String &strToWrite)
{
byte len = strToWrite.length();
EEPROM.write(addrOffset, len);
for (int i = 0; i < len; i++)
{
EEPROM.write(addrOffset + 1 + i, strToWrite[i]);
}
}
String readStringFromEEPROM(int addrOffset)
{
int newStrLen = EEPROM.read(addrOffset);
char data[newStrLen + 1];
for (int i = 0; i < newStrLen; i++)
{
data[i] = EEPROM.read(addrOffset + 1 + i);
}
data[newStrLen] = '\ 0'; // !!! NOTE !!! Remove the space between the slash "/" and "0" (I've added a space because otherwise there is a display bug)
return String(data);
}