I made a simple program with a for loop in another for loop i.e. to feed value in a 2d array ,the loop contains if ,else if &else statement there are total 8 else if statements. then a Serial print to print the outcome , I checked the program in c++ & it runs perfectly but when i upload the program to the board the board does nothing.
I am using ardunio software & the board is diecimila.
please help!!!
What do you want us to do?
Use our magical ways and guess what you've wrote in your program?
It could be a good idea to include your code in your posting...
this is my program
#define infinity 255
#define obsSensor 3
int path[36];
void setup ()
{ // put your setup code here, to run once:
Serial.begin(9600);
}
void loop()
{
int i,j,cost[36][36];
int EEPROMread [] = {1,1,2,1,1,1
,1,1,2,2,2,1
,1,2,1,1,1,2
,1,2,1,2,1,1
,1,1,2,1,1,2
,1,1,2,1,2,1,0
,0,0,6,0,0,0
,0,0,6,0,7,0
,0,7,0,0,0,7
,0,6,0,7,0,0
,0,0,0,0,0,6
,0,5,0,7,0,0};
for(i=0;i<36;i++)
{Serial.print(i);
digitalWrite(13,LOW);
delay(50);
digitalWrite(13,HIGH);
delay(50);
for(j=0;j<36;j++)
{Serial.print(j);
if ((EEPROMread == 2)||(EEPROMread[j] == 2))
- {*
_ cost*[j] = infinity;_
_ }*_
* else*
* {*
* int d;*
* d = j-i;*
* if(d == 0)*
* {*
_ cost*[j] = 0;
}
else if((d == 1) && (i != 5) && (i != 11) && (i != 17) && (i != 23) && (i != 29) && (i != 35))
{
cost[j] = 1;
}
else if((d == 6) && (i != 30) && (i != 31) && (i != 32) && (i != 33 )&& (i != 34) && (i != 35) )
{
cost[j] = 1;
}
else if((d == -6) && (i != 0) && (i != 1) && (i != 2) && (i != 3) && (i != 4) && (i != 5))
{
cost[j] = 1;
}
else if ((d == -1) && (i != 0) && (i != 6) && (i != 12) && (i != 18) && (i != 24) && (i != 30) )
{
cost[j] = 1;
}
else if ((d == 7) && (i != 5) && (i != 11) && (i != 17) && (i != 23) && (i != 29) && (i != 35) && (i != 34) && (i != 33) && (i != 32) && (i != 31) && (i != 30))
{
if( (EEPROMread[i+38] == 6 )||( EEPROMread[i+43] == 5 )){ cost[j] = 1;}
}
else if((d == 5) && (i != 0) && (i != 12) && (i != 18) && (i != 24) && (i != 30) && (i != 31) && (i != 32) && (i != 33) && (i != 34) && (i != 35) && (i != 6) )
{
if( (EEPROMread[i + 36] == 4) || (EEPROMread[i+43] == 7) ){ cost[j] = 1;}
}
else if((d == -7) && (i != 0) && (i != 1) && (i!= 2) && (i!= 3) && (i != 4) && (i != 5) && (i!= 6) && (i!= 12) && (i != 18) && (i != 24)&& (i!= 30) )
{
if ((EEPROMread[i + 36] == 5) || (EEPROMread[i + 31] == 6)){cost[j] = 1;}
}
else if((d == -5) && (i != 0) && (i != 1) && (i!= 2) && (i!= 3) && (i != 4) &&( i != 5 )&&( i!= 11) &&( i!= 17) && (i != 23) && (i != 29) && (i!= 35) )
{
if((EEPROMread[i + 31] == 4) || (EEPROMread[i + 38] == 7) ){cost[j] = 1;}
}
else {cost[j] = infinity;}
}
}}
dijk(cost);
Serial.print("done");_
_for(i=5;i!=0;i=path)
{_
_Serial.print(path);
}
}
void dijk(int cost[36][36])
{
int dist[36], source = 0;_
int i,j,v1=0,v2=0,min_dist;
_ int s[36];
for(i=0;i<36;i++)
{_
dist _= cost[source];
s = 0;
path = source;
}
s[source] = 1;
for(i=1;i<36;i++)
{_
min_dist = infinity;
_ v1 = -1;
for(j=0;j<36;j++)
{
if(s[j] == 0)
{_
if(dist[j]<min_dist)
_ {_
min_dist = dist[j];
_ v1 = j;
}
}
}
s[v1]=1;
for(v2=0;v2<36;v2++)
{
if(s[v2] == 0 )
{
if(dist[v1] + cost[v1][v2] < dist[v2])
{
dist[v2]=dist[v1] + cost[v1][v2];
path[v2]=v1;
}
}
}
}
}*
this program is to find the shortest path in a grid and this going to be a part of bigger program
EEPROMread is an array which is an image of the EEPROM memory ie in this way the data will be stored in the EEPROM in the actual task.
I have given the data my self to check this program
*this works perfectly in my c++ compiler with small change like "Serial.print" become "cout". *_
the programme works if i dont include the function dijk()
int i,j,cost[36][36];
36 * 26 * 2 = 1296 * 2 = 2,592. You just used up 129% of your available SRAM.
oh!! so that's the problem
thanks a lot.