Pages: 1 [2]   Go Down
Author Topic: big array occures freeze  (Read 1732 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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...
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25763
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Doing a bitRead in WriteValue is just a waste of time.
This:
Code:
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?
« Last Edit: May 16, 2011, 11:04:24 am by AWOL » Logged

"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.

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.

Logged

0
Offline Offline
Full Member
***
Karma: 2
Posts: 156
It was all digital
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Flub,

It may not be an issue with your code but this line:
Code:
int count = (seq*4*10*32)+(takt*10*32)+(channel*32)+p; 
has a potential risk of roll-over (at 32,767).

-Fletcher
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A bit of testing shows you can do it with the STL and a minimal amount of mucking around. I fitted 10 sequences on the Uno (just) so you should be OK with the Mega1280.

Code:
#include <iterator>
#include <vector>
#include <new.cpp>

#define SEQUENCES 10
#define BARS 4
#define CHANNELS 10
#define NOTES 32

std::vector<bool> sequenzen (SEQUENCES * BARS * CHANNELS * NOTES);

void setItem (const byte seq, const byte bar, const byte  channel, const byte note, const bool value = true)
{
  int i = (seq * BARS * CHANNELS * NOTES) +
          (bar * CHANNELS * NOTES) +
          (channel * NOTES) +
          note;
  sequenzen [i] = value;        
}

bool getItem (const byte seq, const byte bar, const byte  channel, const byte note)
{
  int i = (seq * BARS * CHANNELS * NOTES) +
          (bar * CHANNELS * NOTES) +
          (channel * NOTES) +
          note;
  return sequenzen [i];
}

void setup ()
{
  Serial.begin (115200);
 
  // testing
  setItem (2, 3, 5, 1);
  setItem (4, 1, 8, 2);

  setItem (SEQUENCES - 1, BARS - 1, CHANNELS - 1, NOTES - 1);
  setItem (0, 0, 0, 0);
  setItem (0, 0, 1, 0);
  setItem (0, 1, 0, 0);
  setItem (1, 0, 0, 0);
  
  Serial.println ("These are set:");
  
  // debugging display
  int j = 0;
  for (std::vector<bool>::const_iterator i = sequenzen.begin ();
       i != sequenzen.end ();
       i++, j++)
     if (*i)
       Serial.println (j);
      
}  // end of setup

void loop ()
{}

The STL "bool" vector uses an efficient storage technique that lets you address bits individually (and fit 8 into a byte). This theoretically would take 1600 bytes (and a memory check confirmed this). My example setItem and getItem show how you just multiply out the wanted sequence/bar/channel/note by the correct number (I hope I got it right) to get to the correct bit in the vector.
 
My numbers are zero-relative (ie. bars 0, 1, 2, 3 rather than 1, 2, 3, 4) but if you prefer one-relative just change the way the index value is calculated. eg.

Code:
int i = ((seq - 1) * BARS * CHANNELS * NOTES) +
         ((bar - 1) * CHANNELS * NOTES) +
         ((channel - 1) * NOTES) +
         note - 1;

STL from here:

http://andybrown.me.uk/ws/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/

Follow installation instructions on that page.
« Last Edit: May 18, 2011, 01:22:46 am by Nick Gammon » Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11690
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Consider an external serial EEPROM or even SDcard to store sequences.
Logged

[ I won't respond to messages, use the forum please ]

Pages: 1 [2]   Go Up
Jump to: