Thanks everybody.
The problem was: trying to get non existing element from array the result will be unpredictable.
Here is the test case:
/*
*/
#include <UTFT.h>
#include <UTouch.h>
#include <Time.h>
#include <avr/pgmspace.h>
// Uncomment the next two lines for the Arduino Mega
UTFT myGLCD(ITDB32S, 38,39,40,41);
UTouch myTouch(6,5,4,3,2);
// Declare which fonts we will be using
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
extern uint8_t SmallFont[];
int x,y,x1,x2,y1,y2;
prog_int16_t Array_02[][7] PROGMEM =
{
{11,12,13,14,15,16}
,{12,70,50,170,1,2}
,{13,180,50,210,3,3}
,{14,40,120,60,2,1}
,{15,70,120,170,1,2}
,{16,180,120,210,3,3}
,{17,40,200,60,2,1}
,{18,70,200,170,1,2}
,{19,180,200,210,3,3}
,{20,40,280,60,2,1}
,{21,70,290,170,1,2}
,{22,180,320,210,3,3}
,{23,180,200,210,3,3}
,{24,40,250,60,2,1}
,{25,70,500,170,1,2}
,{26,180,250,210,3,3}
,{27,180,250,210,3,3}
,{28,180,250,210,3,3}
,{29,180,250,210,3,3}
,{30,180,250,210,3,3}
,{31,180,250,210,3,3}
,{32,180,250,210,3,3}
,{33,180,250,210,3,3}
,{34,180,250,210,3,3}
,{35,180,250,210,3,3}
,{36,180,250,210,3,3}
,{37,180,250,210,3,3}
,{38,180,250,210,3,3}
,{39,180,250,210,3,3}
,{40,180,250,210,3,3}
,{41,180,250,210,3,3}
,{42,180,250,210,3,3}
,{43,180,250,210,3,3}
,{44,180,250,210,3,3}
,{45,180,250,210,3,3}
,{46,180,250,210,3,3}
,{47,180,250,210,3,3}
};
prog_int16_t Array_01 [][7] PROGMEM =
{
{111,40,35,200,1,1}
,{112,40,75,200,1,2}
,{113,40,115,200,1,2}
,{114,40,155,200,1,2}
,{115,40,195,200,1,2}
,{116,40,235,200,1,2}
,{117,40,275,200,1,2}
,{118,40,315,200,1,2}
,{119,40,35,200,1,1}
,{120,40,75,200,1,2}
,{121,40,115,200,1,2}
,{122,40,155,200,1,2}
,{123,40,195,200,1,2}
,{124,40,235,200,1,2}
,{125,40,275,200,1,2}
,{126,40,315,200,1,2}
,{127,40,35,200,1,1}
,{128,40,75,200,1,2}
,{129,40,115,200,1,2}
,{130,40,155,200,1,2}
,{131,40,195,200,1,2}
,{132,40,235,200,1,2}
,{133,40,275,200,1,2}
,{134,40,315,200,1,2}
,{135,40,35,200,1,1}
,{136,40,75,200,1,2}
,{137,40,115,200,1,2}
,{138,40,155,200,1,2}
,{139,40,195,200,1,2}
,{140,40,235,200,1,2}
,{141,40,275,200,1,2}
,{142,40,315,200,1,2}
,{143,40,35,200,1,1}
,{144,40,75,200,1,2}
,{145,40,115,200,1,2}
,{146,40,155,200,1,2}
,{147,40,195,200,1,2}
,{148,40,235,200,1,2}
,{149,40,275,200,1,2}
,{150,40,315,200,1,2}
};
String ActiveScreen ="Array_01";
int ArrayMemory_03[30][7] ;
int Array_Test[7] ;
void setup()
{
// Initial setup
myGLCD.InitLCD();
// myGLCD.clrScr();
myGLCD.fillScr(159,182,205);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 0);
//Time & Alarm:
setTime(18,29,0,1,1,11); // set time to Saturday 18:29:00 Jan 1 2011
Object_SetStatus();
GetArray ("Array_01",50,Array_Test);
}
void loop(){
delay(100);
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
myGLCD.print(" ",1,5);
myGLCD.print(" ",1,20);
myGLCD.print("x:"+String(x),1,5);
myGLCD.print("y:"+String(y),1,20);
int ObjectDetails[7];
if ( ActiveScreen =="Array_01")
{
GetArray ("Array_02",50,Array_Test) ;
}
else if (ActiveScreen=="Array_02"){GetArrayMem();}
else {GetArray ("Array_01",50,Array_Test);}
}
}
void GetArray (String ScreenName,int s,int ObjectDetails[])
{
myGLCD.setFont(SmallFont);
int y1 =20;
for (char i=0;i<s;i++)
{
y1=y1+20;
if (y1>200){y1=20; myGLCD.fillScr(VGA_NAVY);}
if (ScreenName == "Array_02")
{
ObjectDetails[0]=i;
ObjectDetails[1]=pgm_read_word(&(Array_02[i][0]));
ObjectDetails[2]=pgm_read_word(&(Array_02[i][1]));
ObjectDetails[3]=pgm_read_word(&(Array_02[i][2]));
ObjectDetails[4]=pgm_read_word(&(Array_02[i][3]));
ObjectDetails[5]=pgm_read_word(&(Array_02[i][4]));
ObjectDetails[6]=pgm_read_word(&(Array_02[i][5]));
}
if (ScreenName == "Array_01")
{
ObjectDetails[0]=i;
ObjectDetails[1]=pgm_read_word(&(Array_01[i][0]));
ObjectDetails[2]=pgm_read_word(&(Array_01[i][1]));
ObjectDetails[3]=pgm_read_word(&(Array_01[i][2]));
ObjectDetails[4]=pgm_read_word(&(Array_01[i][3]));
ObjectDetails[5]=pgm_read_word(&(Array_01[i][4]));
ObjectDetails[6]=pgm_read_word(&(Array_01[i][5]));
}
myGLCD.printNumI(ObjectDetails[0],0,y1);
myGLCD.printNumI(ObjectDetails[1],40,y1);
myGLCD.printNumI(ObjectDetails[2],80,y1);
myGLCD.printNumI(ObjectDetails[3],120,y1);
myGLCD.printNumI(ObjectDetails[4],160,y1);
myGLCD.printNumI(ObjectDetails[5],200,y1);
myGLCD.printNumI(ObjectDetails[6],240,y1);
delay(1000);
}
//switch the screen to dispaly another array:
if (ActiveScreen == "Array_02") {ActiveScreen="Array_01";}
else {ActiveScreen="Array_02";}
}
void Object_SetStatus() //just initial setup to use some memory
{
//this code for test reason
// later should be updated to get real values from an array
for (int i=0;i<30;i++)
{
ArrayMemory_03[i][0]=i;
ArrayMemory_03[i][1]=i*30;
ArrayMemory_03[i][2]=i*40;
ArrayMemory_03[i][3]=i*50;
}
}
void GetArrayMem ()
{
int ObjectDetails[7];
ActiveScreen = "Array_01";
int y1 =20;
for (int i=0;i<32;i++)
{
y1=y1+20;
if (y1>200){y1=20; myGLCD.fillScr(VGA_NAVY);}
ObjectDetails[0]=i;
ObjectDetails[1]=ArrayMemory_03[i][0];
ObjectDetails[2]=ArrayMemory_03[i][1];
ObjectDetails[3]=ArrayMemory_03[i][2];
ObjectDetails[4]=ArrayMemory_03[i][3];
myGLCD.printNumI(ObjectDetails[0],0,y1);
myGLCD.printNumI(ObjectDetails[1],40,y1);
myGLCD.printNumI(ObjectDetails[2],80,y1);
myGLCD.printNumI(ObjectDetails[3],120,y1);
// myGLCD.printNumI(ObjectDetails[4],160,y1);
// myGLCD.printNumI(ObjectDetails[5],200,y1);
// myGLCD.printNumI(ObjectDetails[6],240,y1);
delay(1000);
}
}