Pages: [1]   Go Down
Author Topic: array processing -  any shortcuts?  (Read 2962 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi -

In my project I am addressing a large matrix of LEDs from Max.  I'd like to maintain a matching array in the firmware, and be able to quickly sync the two (the array with the physical LED matrix).  However looping through all the elements is really slowing things down since they all have to pass thu serial connection.  

I basically want to be able to "flash" many values into the array at once, without having to loop through the array element by element.

If someone could tell me which of these things could work (without loops), and the proper syntax, that would be of immense help:

grid[128]=255;      // Set all values in the int array grid[] to 255

grid[128]=0;         // same as above

grid[2..7]=192;     // set a subset/range of values to 192

Also, if there's any way to do math on multiple elements at once that would be great, too, e.g.

grid[128] = grid[128]-10;  // subtract 10 from all elements in the array

Thanks!

PS: Arduino TOTALLY rocks!

« Last Edit: January 21, 2008, 11:54:40 am by phineus » Logged

Toronto
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However looping through all the elements is really slowing things down since they all have to pass thu serial connection.

I don't know of any ways to do what you're asking, unfortunately (though I wish I did). However, the line I quoted above makes me wonder if there's a faster way to do what you're doing without addressing multiple arrays all at once.

Why do you have to pass all the data through the serial connection? Just extend whatever your serial protocol is to contain commands that allow you to address multiple points on your matrix at once. There's no reason to have more than one serial transmission to update the entire array.

If you'd like I could give a more specific example, if you post more details of your setup.

(By the way, I love your project!  smiley )
« Last Edit: January 21, 2008, 12:35:26 pm by A._Square » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, I was afraid it wasn't possible (or it would have been documented).

Quote
Just extend whatever your serial protocol is to contain commands that allow you to address multiple points on your matrix at once. There's no reason to have more than one serial transmission to update the entire array.

I have been doing this somewhat, creating functions to light an entire column, an entire row, all on, all off, using loops and maxOne(), maxAll() from the Zambetti 7219 code, in response to SimpleMessageSystem ASCII messages from Max.  This is probably going to be the best approach.  But since I am just getting the hang of all this I'm sure there are more efficient ways to do many of these things.

Also, I want to provide as much flexibility as possible to the Max programmers who will be building apps.  So, on the Max side I created a 'virtual stribe' represented by a large [matrixctrl] object.  Ideally the programmer should be able to write an app that interfaces with the 'virtual stribe' and it will interface with the real stribe exactly the same.  We're THIS close... but as the speeds increase (while sequentially lighting up LEDs) we're getting weird behavior.

We have an abstraction which converts changes to the [matrixctrl] Max object (LEDs on or off) into the appropriate maxOne() commands.  But if the messages come out of Max too fast, some of the messages start dropping out, and then all heck breaks loose as the LED display gets more and more out of synch with the [matrixctrl] object.  And when I also try to read the analog sensors during the loop it gets even more hinky.

The [matrixctrl] object can be made to dump it's entire state as a long string, but it seems like feeding all this data across SimpleMessageSystem would take a while...

*

To explain the setup: I have 16 MAX7221s, each one controls an 8x8 grid, 8 grids on the left (1-8), and 8 on the right (9-16) results in a 16x64 LED matrix.

A single 128-element array called grid[] keeps track of the 0-255 bitmask values for each subrow.

Here's the firmware right now: http://www.soundwidgets.com/stribe/code/stribe_04m.pde

*

What it seems like you're implying in your suggestion above is that there could be a way to send all 128 values as a single serial message?  If so that would be amazing: how would do I do this?





« Last Edit: January 21, 2008, 01:23:34 pm by phineus » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6252
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  there is a way of setting all elements of a byte array at once using the function memset. Here is an example:
  
  byte grid[128];  
  memset(grid,255, sizeof(grid));   // set all elements of grid to 255
  
but be careful using it, its very easy to overwrite the array because there is no checking that your parameters are valid and the resulting bugs can be difficult to track down. Using the sizeof macro helps because it will return the size of the array

This does not solve your issue with the serial bottleneck and the suggestion for defining a protocol avoiding sweeping through all elements is a good one
« Last Edit: January 21, 2008, 01:21:58 pm by mem » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is really cool...

Can you explain a little bit the difference between how I would use a byte array vs an int array?
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6252
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that magic only works on bytes. I am not aware of anything similar that works on ints.

I thought yours was a byte array. If the values of grid are from 0 to 255 then you can declare it as an arrray of bytes
« Last Edit: January 21, 2008, 01:40:31 pm by mem » Logged

Toronto
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So, first of all, it looks like you already have commands to turn all of the elements on or off ("w x 100" and "w x 101"). And your "w b int int" and "w e int int" and other codes are similar.

But why not send "int int int int int int int int..." with as many as needed to update whatever it is you want, all in one go, and then have the Arduino distribute it out to the right place. If you're updated random segments of the total 1024 addresses in your system, you could start the transmission off with a 128 byte signal (1024 bits) acting as a mask; only the LEDs corresponding to the high bits are updated. Then have a byte at the end which has the value that you're assigning to them.

Admittedly, I don't know how often you're doing this or if the serial transmission rate is fast enough for your purposes, but you could probably come up with a scheme by which it could work.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If the values of grid are from 0 to 255 then you can declare it as an arrray of bytes

Yes!  So do I use bitwise math?  I'm just learning this - not quite there, yet.

Can you give me an example?  Like, how do I get the values in and out so I can use them as ints in my logic?
Logged

Toronto
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote
If the values of grid are from 0 to 255 then you can declare it as an arrray of bytes

Yes!  So do I use bitwise math?  I'm just learning this - not quite there, yet.

Can you give me an example?  Like, how do I get the values in and out so I can use them as ints in my logic?

No need for bitwise math: a byte is just like an int, except smaller (an int is two bytes attached together). It can hold a value between 0 and 255. If that's all you need, that you can use a byte exactly the same way you're using ints, but it'll only use half the memory.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6252
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yep, just declare grid as in post #3 above and you should be good to go.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome, wow, very psyched to try this out.  

Thanks so much for the insta-help!!!   smiley
Logged

Pages: [1]   Go Up
Jump to: