Go Down

Topic: assign array to a 2D array error (Read 1 time) previous topic - next topic

Antonimo

I use uno and lcd shield, why this code messes up my lcd output? With Serial print it gets stuck. With no print in program it works fine(ir signals received/sent correctly).

Code: [Select]



#define rec_memory  10
int rec_ind = 0;

// Storage for the recorded code
int codeType[rec_memory]={-1}; // The type of code
unsigned long codeValue[rec_memory]; // The code value if not raw
//unsigned int rawCodes[rec_memory][RAWBUF]; // The durations if raw
int codeLen[rec_memory]; // The length of the code
int toggle[rec_memory]={0}; // The RC5/6 toggle state


typedef int rawCodesDef[RAWBUF];

struct RawCodes {
   rawCodesDef x;
};

RawCodes rawCodes[rec_memory];



////// somewhere in code /////


   RawCodes tmpRawCodes;
   
   for(int i=0; i<RAWBUF;i++){
//        tmp_rawCodes[i] = 1;
       tmpRawCodes.x[i] = i+2;
   }
 //  for(int i=0; i<10;i++){
  //     rawCodes[1][i] = tmp_rawCodes[i];
   //}

   rawCodes[1] = tmpRawCodes; // problem code <<<<<<<<<
   



in my debugging i only lcd.print "hello +time()"
with  "//rawCodes[1] = tmpRawCodes;" commented out i get " hello 1" , "hello 2" etc

with " rawCodes[1] = tmpRawCodes;"
i get "hello 1$%@...", "hello 2%5*" etc

txs!!!

sixeyes

I'm not sure I follow you code but could it be you want to replace

Code: [Select]
rawCodes[1] = tmpRawCodes;

with

Code: [Select]
memcpy(&rawCodes[1], tmpRawCodes, sizeof(RawCodes));

Iain

Antonimo

i made a simpler task and it haz the same affect

Code: [Select]


#include <LiquidCrystal.h>
#include <IRremote.h>
 
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5




#define rec_memory  10
int rec_ind = 0;

// Storage for the recorded code
int codeType[rec_memory]={-1}; // The type of code
unsigned long codeValue[rec_memory]; // The code value if not raw
//unsigned int rawCodes[rec_memory][RAWBUF]; // The durations if raw
int codeLen[rec_memory]; // The length of the code
int toggle[rec_memory]={0}; // The RC5/6 toggle state


typedef int rawCodesDef[RAWBUF];

struct RawCodes {
   rawCodesDef x;
};

RawCodes rawCodes[rec_memory];




// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0);      // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 50)   return btnRIGHT;
if (adc_key_in < 195)  return btnUP;
if (adc_key_in < 380)  return btnDOWN;
if (adc_key_in < 555)  return btnLEFT;
if (adc_key_in < 790)  return btnSELECT;  
return btnNONE;  // when all others fail, return this...
}

void setup()
{
lcd.begin(16, 2);              // start the library
lcd.setCursor(0,0);
lcd.print("Push the buttons"); // print a simple message

Serial.begin(9600);
}
 
void loop()
{
lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
lcd.print(millis()/1000);      // display seconds elapsed since power-up
//Serial.println(millis()/1000);

lcd.setCursor(0,1);            // move to the begining of the second line
lcd_key = read_LCD_buttons();  // read the buttons

   if (lcd_key == btnDOWN){

       RawCodes tmp_rawCodes;
   
       
       for(int i=0; i<RAWBUF;i++){  // RAWBUF == 76
           tmp_rawCodes.x[i] = i+1;
           //rawCodes[1].x[i] = i;
       }
       
       for(int i=0; i<10;i++){
           rawCodes[1].x[i] = tmp_rawCodes.x[i];  // problem 2.. <<<<<<<<<<<<
       }
       //rawCodes[1] = tmpRawCodes; // problem 1
       
       lcd.setCursor(0,0);
       
       for(int i=0; i<10; i++){
            Serial.print(rawCodes[1].x[i]);
            Serial.print(" ");
           
            //lcd.print(rawCodes[1].x[i]);
            //lcd.print("t");
        }

       Serial.println(" ");
 }
}




and using your code i get

sketch_jan17b:89: error: cannot convert 'RawCodes' to 'const void*' for argument '2' to 'void* memcpy(void*, const void*, size_t)'

sixeyes

Sorry for the typo.

Should have been an & in front of the second parameter.

Antonimo

ohz, thx.

Code: [Select]
rawCodes[1] = tmpRawCodes;  
works fine too.


found the problem by the way, it appears that i was out of ram...
i use 76*10 ints.
when reduced it to 76*9 ints it worked.
Code: [Select]
#define rec_memory  9

thats why disabling Serial was working, i guess Serial uses lots of ram? (output buffer?)

need other way to log my ir codes =)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy