Go Down

Topic: Error msg in PROGMEM (Read 2414 times) previous topic - next topic

AWOL

Looks to me like the "for" loop needs some work too.

alhootti

Thanks for all

but that issue still no change

Now im using this code but get this Error msg :
CityNames:10: error: cannot convert 'const long int (*)[1][8]' to 'const char* const' in initialization

Code: [Select]

#include <avr/pgmspace.h>
const long LONDON[][1][8] PROGMEM = {
{ 1, 1, 539, 700, 1225, 325, 545, 701 },
{ 2, 1, 540, 700, 1225, 325, 545, 701 },
};
const long NEWYUORK[][1][8] PROGMEM = {
{ 3, 1, 540, 701, 1226, 326, 546, 702 },
{ 4, 1, 540, 701, 1226, 327, 547, 702 },
};
const char* const CityNames[] PROGMEM = {LONDON, NEWYUORK}; //  <--- Error HIGHLIGHT
char buffer[30];   
void setup()
{
  Serial.begin(9600);
  while(!Serial);
  Serial.println("OK");
}

void loop()
{
 int i = 1;
    strcpy_P(buffer, (char*)pgm_read_word(&(CityNames[i])));
    Serial.println(buffer);
    delay(500);
}

AWOL

#17
Mar 02, 2016, 12:40 pm Last Edit: Mar 02, 2016, 12:51 pm by AWOL
Take a really close look at reply #13.

Code: [Select]
const long LONDON[][1][8] PROGMEM = {
{ 1, 1, 539, 700, 1225, 325, 545, 701 },
{ 2, 1, 540, 700, 1225, 325, 545, 701 },
};

You've told the compiler there's a three dimensional array, where the second dimension is a single element, and you've initialised the array with two dimensions.
That's not at all confusing.

alhootti

Now im using 3 dimintion but still get Error:
error: invalid types 'const char[int]' for array subscript

Code: [Select]


#include <avr/pgmspace.h> // Bur tamam
#include <EEPROM.h>
const long LONDON[10][10][8] PROGMEM = {
{ 1, 2, 539, 700, 1225, 325, 545, 701 },
{ 2, 3, 540, 700, 1225, 325, 545, 701 },
{ 3, 4, 540, 701, 1226, 326, 546, 702 },
{ 4, 5, 540, 701, 1226, 327, 547, 702 },
{ 5, 6, 541, 701, 1227, 327, 547, 703 },
{ 6, 7, 541, 701, 1227, 328, 548, 704 },
{ 7, 8, 541, 702, 1228, 329, 549, 704 },
{ 8, 10, 541, 702, 1228, 329, 549, 705 },
{ 9, 11, 542, 702, 1229, 330, 550, 706 },
{ 10, 12, 542, 702, 1229, 331, 551, 706 },
};
const long NEWYUORK[10][10][8] PROGMEM = {
{ 1, 2, 555, 720, 1230, 335, 545, 708 },
{ 2, 3, 540, 700, 1225, 345, 545, 701 },
{ 3, 4, 540, 701, 1226, 326, 546, 702 },
{ 4, 5, 540, 701, 1226, 327, 547, 702 },
{ 5, 6, 541, 701, 1227, 327, 547, 703 },
{ 6, 7, 541, 701, 1227, 328, 548, 704 },
{ 7, 8, 541, 702, 1228, 329, 549, 704 },
{ 8, 9, 541, 702, 1228, 329, 549, 705 },
{ 9, 10, 542, 702, 1229, 330, 550, 706 },
{ 10, 11, 542, 702, 1229, 339, 551, 706 },
};
const char* const CityNames[] PROGMEM = {LONDON, NEWYUORK}; //  <--- Error HIGHLIGHT <-------------------------
int CityCode = EEPROM.read(7); // CityCode as index
void setup()
{
 
}
void loop()
{
int FA;
int day = 1;
int month = 2;

    for (int r = 0; r <= 11; r++)
  {
    if ((pgm_read_word( & CityNames[CityCode][r][0]) == day) && (pgm_read_word( & CityNames[CityCode][r][1]) == month))
    {
   FA = pgm_read_word( & CityNames[CityCode][r][2] );
    }
   }
}




AWOL

Code: [Select]
const long LONDON[10][10][8] PROGMEM = {
You don't have ten cities, you have two cities.


Uncompiled, untested, from your original post)
Code: [Select]
#include <avr/pgmspace.h>
#include <EEPROM.h>
const long CITIES [2][10][8] PROGMEM = {
  {
{ 1, 1, 539, 700, 1225, 325, 545, 701 },
{ 2, 1, 540, 700, 1225, 325, 545, 701 },
{ 3, 1, 540, 701, 1226, 326, 546, 702 },
{ 4, 1, 540, 701, 1226, 327, 547, 702 },
{ 5, 1, 541, 701, 1227, 327, 547, 703 },
{ 6, 1, 541, 701, 1227, 328, 548, 704 },
{ 7, 1, 541, 702, 1228, 329, 549, 704 },
{ 8, 1, 541, 702, 1228, 329, 549, 705 },
{ 9, 1, 542, 702, 1229, 330, 550, 706 },
{ 10, 1, 542, 702, 1229, 331, 551, 706 }
},
{
{ 1, 1, 539, 720, 1230, 325, 545, 708 },
{ 2, 1, 540, 700, 1225, 345, 545, 701 },
{ 3, 1, 540, 701, 1226, 326, 546, 702 },
{ 4, 1, 540, 701, 1226, 327, 547, 702 },
{ 5, 1, 541, 701, 1227, 327, 547, 703 },
{ 6, 1, 541, 701, 1227, 328, 548, 704 },
{ 7, 1, 541, 702, 1228, 329, 549, 704 },
{ 8, 1, 541, 702, 1228, 329, 549, 705 },
{ 9, 1, 542, 702, 1229, 330, 550, 706 },
{ 10, 1, 542, 702, 1229, 339, 551, 706 }
}
};

int CityCode;

int day, month, FA, SH,DH, AS, MA, ESH;

void setup()
{
  CityCode = EEPROM.read(7);
}

void loop()
{
  char CityName = CityCode - 1;

  for (int r = 0; r < 10; r++)
  {
    if ((pgm_read_word( &CITIES[CityName][r][ 0 ]) == day) && (pgm_read_word( & CITIES [CityName][ r ][ 1 ]) == month))
    {
   FA = pgm_read_word( & CITIES[CityName][ r ][ 2 ] );
   SH = pgm_read_word( & CITIES[CityName][ r ][ 3 ] );
   DH = pgm_read_word( & CITIES[CityName][ r ][ 4 ] );
   AS = pgm_read_word( & CITIES[CityName][ r ][ 5 ] );
   MA = pgm_read_word( & CITIES[CityName][ r ][ 6 ] );
   ESH = pgm_read_word( & CITIES[CityName][ r ][ 7 ] );
    }
  }
}

alhootti

#20
Mar 02, 2016, 04:35 pm Last Edit: Mar 02, 2016, 04:43 pm by alhootti
Code: [Select]

const long CITIES [2][10][8] PROGMEM = {
  {
{ 1, 1, 520, 750, 1245, 340, 515, 710 },
{ 2, 1, 540, 700, 1225, 325, 545, 701 },
{ 3, 1, 540, 701, 1226, 326, 546, 702 },
{ 4, 1, 540, 701, 1226, 327, 547, 702 },
{ 5, 1, 541, 701, 1227, 327, 547, 703 },
{ 6, 1, 541, 701, 1227, 328, 548, 704 },
{ 7, 1, 541, 702, 1228, 329, 549, 704 },
{ 8, 1, 541, 702, 1228, 329, 549, 705 },
{ 9, 1, 542, 702, 1229, 330, 550, 706 },
{ 10, 1, 542, 702, 1229, 331, 551, 706 }
},
{
{ 1, 1, 539, 720, 1230, 325, 545, 708 },
{ 2, 1, 540, 700, 1225, 345, 545, 701 },
{ 3, 1, 540, 701, 1226, 326, 546, 702 },
{ 4, 1, 540, 701, 1226, 327, 547, 702 },
{ 5, 1, 541, 701, 1227, 327, 547, 703 },
{ 6, 1, 541, 701, 1227, 328, 548, 704 },
{ 7, 1, 541, 702, 1228, 329, 549, 704 },
{ 8, 1, 541, 702, 1228, 329, 549, 705 },
{ 9, 1, 542, 702, 1229, 330, 550, 706 },
{ 10, 1, 542, 702, 1229, 339, 551, 706 }
}
};





Im very glad to see it is working but there is small issue.
when i change CityCode it always get same result


 if CodeCity = 0  it must be
Code: [Select]

520, 750, 1245, 340, 515, 710


 if CodeCity = 1  it must be

Code: [Select]

539, 720, 1230, 325, 545, 708


if CodeCity = 2  no result at all

AWOL

Code: [Select]
520, 750, 1245, 340, 515, 710
First time these values have been mentioned.

So, add another dimension.

You can't expect custom solutions from code that doesn't even compile.

alhootti

Its working properly with city number 2 not 1 even i changed CityCode

all time i got thes vlaues

Code: [Select]

539, 720, 1230, 325, 545, 708

alhootti

Mr.AWOL
Thank you sooooooooooooooooo muuuuuuuuuuuuuuck
 all thing is fine now and the problem has been solved
thank you for your cooperation
 :smiley-grin:

alhootti

i have 366 arry (Number of Days in one entire year)

Code: [Select]

const long CITIES [3][366][8] PROGMEM



i got this msg:
error: size of array 'CITIES' is too large

AWOL

#25
Mar 02, 2016, 06:27 pm Last Edit: Mar 02, 2016, 06:28 pm by AWOL
So, make them uint16_t, instead of long
Better still, make it an array of struct.

alhootti

Code: [Select]

const int16_t CITIES [2][366][8] PROGMEM

no Error
but the Result is = 0

AWOL

Code: [Select]

const int16_t CITIES [2][366][8] PROGMEM

no Error
but the Result is = 0
That's tough.

Go Up