When I upload the code attached below, it works fine for a few minutes and then the entire code freezes, the buttons don't work, the weight does not update, I need to reset the entire code to make sure it works. Initially thought it was a memory issue so even reduced the no. of products and other stuff but nothing worked. Please help me out, I have a deadline.
I see a number of warning: iteration N invokes undefined behavior (where N is a number) when I compile your code; they are more than likely the cause of your problem (but I did not dig deep into it. I suggest that you set compiler warnings (in file -> preferences in the IDE) to All.
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\Screens.ino: In function 'bool pwScreen()':
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\Screens.ino:147:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(number==password){
~~~~~~^~~~~~~~~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\Screens.ino:157:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(number!=password){
~~~~~~^~~~~~~~~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\Screens.ino:177:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\updateEEPROM.ino: In function 'updateEEPROM()':
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\updateEEPROM.ino:16:33: warning: iteration 20 invokes undefined behavior [-Waggressive-loop-optimizations]
dtostrf(weights[prodIndex][0], 7, 1, tempBuf);
~~~~~~~~~~~~~~~~~~~~^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\updateEEPROM.ino:14:34: note: within this loop
for(byte prodIndex=0; prodIndex<21; prodIndex++){ //product lower lims
~~~~~~~~~^~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\updateEEPROM.ino:18:65: warning: iteration 7 invokes undefined behavior [-Waggressive-loop-optimizations]
EEPROM.update(prodIndex*7+byteIndex+221, tempBuf[byteIndex]);
~~~~~~~~~~~~~~~~~^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\updateEEPROM.ino:17:36: note: within this loop
for(byte byteIndex=0; byteIndex<8; byteIndex++){
~~~~~~~~~^~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\updateEEPROM.ino: In function 'loadEEPROM()':
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:8:19: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(tempBuf[byteIndex]);
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:5:36: note: within this loop
for(byte byteIndex=0; byteIndex<10; byteIndex++){
~~~~~~~~~^~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:24:26: warning: iteration 20 invokes undefined behavior [-Waggressive-loop-optimizations]
weights[prodIndex][0]=atof(tempBuf);
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:17:34: note: within this loop
for(byte prodIndex=0; prodIndex<21; prodIndex++){ //product lower lims
~~~~~~~~~^~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:22:19: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(tempBuf[byteIndex]);
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:20:36: note: within this loop
for(byte byteIndex=0; byteIndex<7; byteIndex++){
~~~~~~~~~^~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:36:26: warning: iteration 20 invokes undefined behavior [-Waggressive-loop-optimizations]
weights[prodIndex][1]=atof(tempBuf);
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:29:34: note: within this loop
for(byte prodIndex=0; prodIndex<21; prodIndex++){ //product upper lims
~~~~~~~~~^~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:34:19: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(tempBuf[byteIndex]);
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:32:36: note: within this loop
for(byte byteIndex=0; byteIndex<7; byteIndex++){
~~~~~~~~~^~
Archiving built core (caching) in: C:\Users\sterretje\AppData\Local\Temp\arduino_cache_838555\core\core_arduino_avr_leonardo_4e759d11e131d256fe058d84342dcde1.a
C:\Users\sterretje\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino\main.cpp: In function 'main':
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:36:26: warning: iteration 20 invokes undefined behavior [-Waggressive-loop-optimizations]
weights[prodIndex][1]=atof(tempBuf);
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:29:34: note: within this loop
for(byte prodIndex=0; prodIndex<21; prodIndex++){ //product upper lims
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:34:19: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(tempBuf[byteIndex]);
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:32:36: note: within this loop
for(byte byteIndex=0; byteIndex<7; byteIndex++){
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:24:26: warning: iteration 20 invokes undefined behavior [-Waggressive-loop-optimizations]
weights[prodIndex][0]=atof(tempBuf);
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:17:34: note: within this loop
for(byte prodIndex=0; prodIndex<21; prodIndex++){ //product lower lims
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:22:19: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(tempBuf[byteIndex]);
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:20:36: note: within this loop
for(byte byteIndex=0; byteIndex<7; byteIndex++){
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:8:19: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations]
Serial.print(tempBuf[byteIndex]);
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:5:36: note: within this loop
for(byte byteIndex=0; byteIndex<10; byteIndex++){
^
C:\Users\sterretje\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino\WString.cpp:694:15: warning: iteration 20 invokes undefined behavior [-Waggressive-loop-optimizations]
if (index >= len) { return; }
^
C:\Users\sterretje\Documents\Arduino\Forums\899048\wc4.8\wc4.8\loadEEPROM.ino:2:34: note: within this loop
for(byte prodIndex=0; prodIndex<21; prodIndex++){ //load product names
^
Sketch uses 20020 bytes (69%) of program storage space. Maximum is 28672 bytes.
Global variables use 994 bytes (38%) of dynamic memory, leaving 1566 bytes for local variables. Maximum is 2560 bytes.
String productNames[20]
...
for(byte n=0; n<21; n++){ // <-- productNames can store 20 elements, arrays indices range from 0 to size-1, so this should be 20 not 21
productNames[n]= "PRODUCTXYZ\0";
In many for loops you have the same error
Another example in loadEEPROM.ino :
char tempBuf[8];
...
for(byte byteIndex=0; byteIndex<10; byteIndex++){
EEPROM.get(prodIndex*10+byteIndex, tempBuf[byteIndex]); // <-- tempBuf can store 8 elements but you try to store 10 elements in it
Fix ALL those buffer overflows and ALL compile warnings