Go Down

Topic: big array occures freeze (Read 1 time) previous topic - next topic

Flub

Thank you all guys! i got it...
I didnt knew that a byte is something like : B00000000...

Code: [Select]

byte sequenzen[2560];
...
void setup() {
for (int i = 0; i < 2560; i++) {
   sequenzen[i]=B00000000;
}
...
}
...
boolean ReadValue(int seq, int takt, int channel, int p) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;
count--;
int x = count % 8;
int x2 = (count-x)/8;
return bitRead(sequenzen[x2],x);
}

void WriteValue(int seq, int takt, int channel, int p, boolean value) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p; 
count--;
int x = count % 8;
int x2 = (count-x)/8;
bitRead(sequenzen[x2],x); ;
bitWrite(sequenzen[x2],x,value);
}


this works fine. Now its a pitty that this doesnt fit on the eprom, so i cannot save the sequenzes while the device is off...

AWOL

#16
May 16, 2011, 06:02 pm Last Edit: May 16, 2011, 06:04 pm by AWOL Reason: 1
Doing a bitRead in WriteValue is just a waste of time.
This:
Code: [Select]
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;
count--;
int x = count % 8;
int x2 = (count-x)/8;

is common code - why not factor it into a single function?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

jraskell

Quote
Now its a pitty that this doesnt fit on the eprom, so i cannot save the sequenzes while the device is off...


A microSD shield would give you access to up to 2GB of storage.

Flub

oh i forgot to clear the function out of mistakes... i need two for several purposes for example copy and pasting sequences.

Code: [Select]

boolean ReadValue(int seq, int takt, int channel, int p, int Switch) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p;
int x = count % 8;
int x2 = (count-x)/8;
count=-1;
boolean BIT = bitRead(sequenzen[x2],x);
if (Switch) {
  bitWrite(sequenzen[x2],x,inv(BIT));
} else {
  return BIT;
}
}

void WriteValue(int seq, int takt, int channel, int p, boolean value) {
takt--;
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p; 
int x = count % 8;
int x2 = (count-x)/8;
count=-1;
bitWrite(sequenzen[x2],x,value);
}


if I see this the right way.... i dont even need the micro sd thing because ive got 4kB eprom : http://arduino.cc/en/Main/ArduinoBoardMega2560

with the Mega1280 ...

I ll see how to save it on the eprom.


Fletcher Chr

Hi Flub,

It may not be an issue with your code but this line:
Code: [Select]
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p; 

has a potential risk of roll-over (at 32,767).

-Fletcher

Go Up