How to read hard-coded data array into variables ?

Hi Everyone,

I want to hard code some arrays of data into some array variables

I know I can do it in variable declaration stage, for example :

unsigned char Internal_Preset[38]=

{0x00,0x19,0x20,0x59,0x40,0x40,0x8,0x00,0x18,0x20,0xA,0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x40,0x64,0x00,0x00

,0x40,0x40,0x40,0x7F,0x00,0x64,0x40,0x40,0x40,0xA,0x00,0x00,0x40,0x00,0x00,0x00} ;

But if I have some list of known value that can be hard-code into the program

list 1 : {0x00,0x17,.........,0x00} ;
list 2 : {0x30,0x17,.........,0x7f} ;
..............
...............
list n : {0x30,0x17,.........,0xb1} ;

and want to store one of these list into the variable Internal_Preset[38] during program run, e.g. list 2,

I can only write tendious statement like that :

Internal_Preset[0]=0x30 ;
Internal_Preset[1]=0x17 ;
........
........
........
Internal_Preset[37]=0x7f ;

Is there any method that I can read the data list like that :
Internal_Preset={0x30,0x17,.........,0x7f} ;

Thanks !

want to store one of these list into the variable Internal_Preset[38] during program run

Why would you want to do that? How is it different than putting the data there at declaration time?

You can do:

const unsigned char PROGMEM Internal_Preset[38]=  {0x00,0x19,0x20,0x59,0x40,0x40,0x8,0x00,0x18,0x20,  ...};

void loop() {
  unsigned char runtime_var[sizeof(Internal_Preset);
  memcpy_P(runtime_var, Internal_Preset, sizeof(Internal_Preset));
      :

memcpy() variants in general are used to copy large chunks of data around.

You can redeclare the variable, maybe
unsigned char Internal_Preset = .....

You can put each of your hard coded arrays/lists into flash (search PROGMEM) and then copy the values into your array 'Internal_Preset' using a loop when needed.

http://playground.arduino.cc/Main/PROGMEM

Edit: just like westfw is doing.

Thank you westfw !

Actually my program is a sound module patches selection/editing/management system. I am using a Mega2560 and use TFT display.

There are too many text that need to stroe, so although the Mega has 8k SRAM and 4k EEPROM, it is still not really sufficient to store all the text, and no room to stroe the Internal_Preset in the flash memory

So I want to store the preset data in the program as statememt,and avoid the insufficient memeory problem.

When I need to change a patch and do some processing, I can just use the statement :

Internal_Preset={0x30,0x17,.........,0x7f} ;

Also, I have these presets existing in the form of {0x30,0x17,.........,0x7f} already.

if I code these preset in these way :

Internal_Preset[0]=0x30 ;
Internal_Preset[1]=0x17 ;
........
........
........
Internal_Preset[37]=0x7f ;

there's too much extra work to do !

mistergreen:
You can redeclare the variable, maybe
unsigned char Internal_Preset = .....

How to redeclare the same variable in the program ?

There are too many text that need to stroe, so although the Mega has 8k SRAM and 4k EEPROM, it is still not really sufficient to store all the text, and no room to stroe the Internal_Preset in the flash memory
So I want to store the preset data in the program as statememt,and avoid the insufficient memeory problem.

That may be what you think you should do, but you probably REALLY need to look into the PROGMEM stuff that lets you store your text in bulk, directly in flash.
Start here: http://arduino.cc/en/Reference/PROGMEM