A simple problem I'm sure.

Stuck with a problem in your code? Seek help here.

A simple problem I'm sure.

Postby TravisCucore » January 6th, 2015, 12:27 pm

I've been working on an AVR project (My first) and am in need of what I'm sure is a simple solution to a problem I have with an iterative statement. You see I'm not real great at C++ so I imagine someone out there will find this question to be rather silly.

I have several variables initialized as the following:

Code: Select all
int   Row0 [16];
int   Row1 [16];
int   Row2 [16];
int   Row3 [16];
int   Row4 [16];
int   Row5 [16];


I want to tumble through these rows with a for statement. I know how to make it through each array but have no idea how to use a variable to affect my reference to another variable. The goal is to output each "Row" to a shift register, then shift another register that's being used to strobe the columns. Basically I'm driving a grid of LEDs. I could do this with multiple blocks representing each row but I run out of memory if I do that.

This is what I have:

Code: Select all
int DrawBoard(void)
{
   Mask_High;
   for (int i = 5; i > -1; i--)
   {
      for (int j = 6; j >-1; j--)
      {
         if (Row"i" [j] == 1)     // I've obviously done this wrong but I'm looking for a way to meld the value of j with Row
         {
            Serial_High;
         }
         else
         {
            Serial_Low;
         }
      }
   }
   return 0;


If i'm going about this entirely the wrong way, I'm open to hearing a better way :)

Thanks in advance,
Travis Cucore
TravisCucore
 
Posts: 46
Joined: May 14th, 2013, 1:02 am

Re: A simple problem I'm sure.

Postby Osgeld » January 6th, 2015, 7:29 pm

I would use a 2d array, then its just a yx for loop

Code: Select all
int data [6][16];

data[1][12] = 0xff; //example on how to populate a value

for (int y= 5; y > -1; y--)
{
    for (int x= 15; x > -1; x--)
    {
        doSomething(data[y], data[x]);
    }
}


so that you will start on row y, and loop though all the x values before changing to a new row y
User avatar
Osgeld
 
Posts: 725
Joined: January 25th, 2011, 6:16 pm

Re: A simple problem I'm sure.

Postby TravisCucore » January 7th, 2015, 1:39 pm

Thanks a bunch. That helped a-lot. I wasn't aware you could compound them like that.
TravisCucore
 
Posts: 46
Joined: May 14th, 2013, 1:02 am


Return to Help Me! Software

Who is online

Users browsing this forum: No registered users and 1 guest