I am looking for the most compact way of copying a byte array into another byte array.
These byte arrays contain data that I am expanding into a 35 byte array so I probably can't
use string functions. I am using a tiny84 and am running out of space...
I have 35 arrays that have 5 bytes per array and I am trying to save programming space but
need to select one of these arrays which I am doing with a switch.
Which method would save the most programming space:
memcpy(FonType, fontA, sizeof FonType);
or
int 1 = 5;
while(i--) *FonType++ *FonType++;
or something else?
here is a snippet of my code:
byte fontA[5]= {116,127,24,198,32};
byte fontB[5]= {244,99,232,199,192};
byte fontC[5]= {116,97,8,69,192};
byte fontD[5]= {244,99,24,199,192};
// there are 31 more of these
byte SELFONT[35];
byte FonType[5]= {0,0,0,0,0};
byte hexval[8] = {128,64,32,16,8,4,2,1};
byte dsread =0; // read dipswitch input variable
byte pattrn = 0; // font pattern choice
void setup() {
pinMode(Bit0, INPUT_PULLUP); // dipswitch 1
pinMode(Bit1, INPUT_PULLUP); // dipswitch 2
pinMode(Bit2, INPUT_PULLUP); // dipswitch 3
pinMode(Bit3, INPUT_PULLUP); // dipswitch 4
pinMode(Bit4, INPUT_PULLUP); // dipswitch 5
pinMode(Bit5, INPUT_PULLUP); // dipswitch 6
// read dipswitch and assign pattern
dsread = digitalRead(Bit0); // get dipswitch 1 setting
if(dsread == HIGH){ pattrn++; }
dsread = digitalRead(Bit1);
if(dsread == HIGH){ pattrn += 2; }
dsread = digitalRead(Bit2);
if(dsread == HIGH){ pattrn += 4; }
dsread = digitalRead(Bit3);
if(dsread == HIGH){ pattrn += 8; }
dsread = digitalRead(Bit4);
if(dsread == HIGH){ pattrn += 16; }
dsread = digitalRead(Bit5);
if(dsread == HIGH){ pattrn += 32; }
switch (pattrn) {
case 0:
memcpy(FonType, fontA, sizeof FonType);
break;
case 1:
memcpy(FonType, fontB, sizeof FonType);
break;
case 2:
memcpy(FonType, fontC, sizeof FonType);
break;
case 3:
memcpy(FonType, fontD, sizeof FonType);
break;
} // --- end of switch
// ---- This next section expands the 5 byte array (FonType[5]) into a 35 byte array (SELFONT[35]) ----
ndx = 0; // ndx selects the hex value for conversion to binary
byte indx = 0; // indx selects which byte of FonType is being decoded (expanded)
for(byte i=0; i < 35; i++) { // i selects the byte of SELFONT that is getting set up
if (FonType[indx] >=hexval[ndx]) { // here we check if the selected byte of FonType should be set
SELFONT[i] = 1; // if yes, set SELFONT[i] = 1
FonType[indx] = FonType[indx]- hexval[ndx]; // then remove that value from FonType[indx]
}
else {
SELFONT[i] = 0; // otherwise set SELFONT[i] = 0
}
ndx++; // increment the hex value
if (ndx >= 8) { // if all hex values hav ebeen applied, reset for the next FonType byte to be converted
ndx = 0;
indx++; // increment to select the next byte of FonType
}
}
} // end of setup