Trying to redeclare an array with different....


number of elements , content original declared.

code: [select]
//hello trying redeclare varible array (bytes),
#define countof(a) (sizeof(a) / sizeof(a[0]))
byte setdeadtimeic[16]; //well trying create kind of empty "buffer" first, later will
//that have more elements ever use in future code.my idea reserve more
//memory space required , when redeclare array future in code (with different number of elements , different
//content)
void setup()
{
  serial.begin(9600);
   myloop();
}




void loop()
{
 //

}


void myloop()
{
 byte a,b; //those varibles dependant on rotary encoder, when rotate mechanical encoder "a" , "b" change
 //those variables in 0x format
 if((a==0x2b) && (b==0x2b))
 {
byte setdeadtimeic[]={0x2b,0xe3,0x00,0x36,a,0x2b,0x00,b,0x2b};
 }
if((a==0x2b) && (b!=0x2b))
 {
byte setdeadtimeic[]={0x2b,0xe3,0x00,0x36,a,0x2b,0x00,b};    
 }
if((a!=0x2b) && (b!=0x2b))
 {
byte setdeadtimeic[]={0x2b,0xe3,0x00,0x36,a,0x00,b};
 }
 //as can see code above  i trying "insert" element after right after "a" or "b" or both
 //dependant on if "a","b" or both equal 0x2b
 for(int ee=0;ee<countof(setdeadtimeic);ee++)
 {
   serial.print(setdeadtimeic[ee],byte);
 }
 
 
}


we'll if can show specific solution problem or somekind of workaround grateful :-/

you can't make sizeof(setdeadtimeic) change after initial declaration, hold intended size in separate variable.

code: [select]
[glow]byte[/glow] setdeadtimeic[]={0x2b,0xe3,0x00,0x36,a,0x2b,0x00,b,0x2b};

"byte" here means try declare new variable die @ following "}". make assignments individual array positions instead, e.g.

code: [select]
setdeadtimeic[4] = a;
setdeadtimeic[5] = 0x2b;
...



Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Trying to redeclare an array with different....


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums