74HC259, Compiling Error...

boolean HC259_address[] = {0,0,0};  // Sets a 3-bit address array
boolean HC259_data[] = {0,0,0,0,0,0,0,0};  // Sets an 8-bit data array

// Define latch address pins and data pin
int HC259_A_pin = 4;
int HC259_B_pin = 3;
int HC259_C_pin = 2;
int HC259_data_pin = 5;

void setup()
{
  pinMode(HC259_A_pin, OUTPUT);
  pinMode(HC259_B_pin, OUTPUT);
  pinMode(HC259_C_pin, OUTPUT);
  pinMode(HC259_data_pin, OUTPUT);
}

void loop()
{

  HC259_data[] = {0,1,0,1,0,1,0,1};
  HC259_send_data();  // Send 01010101 to the chip, lighting LEDs 2, 4, 6, and 8
  delay(1000);
  HC259_data[] = {1,0,1,0,1,0,1,0};
  HC259_send_data();  // Send 10101010 to the chip, lighting LEDs 1, 3, 5, and 7
  delay(1000);

}

void HC259_send_data()  // Takes data from HC259_data[] and sends it, bit by bit, to each bit register in the HC259
{

  for (i = 0; i <= 7; i ++) // For each array element
  {
    HC259_set_address(i);  // Choose the right pin
    digitalWrite(HC259_data_pin,HC259_data[i]);  // Send the bit to be stored on that pin
  }

}

void HC259_set_address(int latch)  // Translates an input between 0 and 7 into the correct bit sequence to send to the latch registers, addressing the desired pin
{

  switch (latch)
  {

    case 0:
      HC259_address[] = {0,0,0}
      break;
    case 1:
      HC259_address[] = {0,0,1}
      break;
    case 2:
      HC259_address[] = {0,1,0}
      break;
    case 3:
      HC259_address[] = {0,1,1}
      break;
    case 4:
      HC259_address[] = {1,0,0}
      break;
    case 5:
      HC259_address[] = {1,0,1}
      break;
    case 6:
      HC259_address[] = {1,1,0}
      break;
    case 7:
      HC259_address[] = {1,1,1}
      break;
    default:
      // Nothing

  }

  // Send the data to the latch pins to tell it which bit to address
  digitalWrite(HC259_A_pin,HC259_address[0]);
  digitalWrite(HC259_B_pin,HC259_address[1]);
  digitalWrite(HC259_C_pin,HC259_address[2]);

}

That’s what I’ve got. When I try to compile, it gives me this error:

In function 'void loop()':
error: expected primary-expression before ']' token In function 'void HC259_send_data()':
 In function 'void HC259_set_address(int)':

What the heck does that mean? As far as my experience with C/C++ and PHP has shown me, I’ve done everything correct. Did I make some stupid beginner mistake, or is this a limitation of Arduino that I wasn’t aware of?

Thanks!

HC259_address[] = {0,0,0} [glow]  [/glow]
 HC259_data[] = {0,1,0,1,0,1,0,1};

I've done everything correct

Hmmm.

is this a limitation of Arduino that I wasn't aware of?

No, that's a lack of understanding of C/C++.

The Arduino arrays page said that the IDE automatically counts the number of elements being put into an array, so I don't have to explicitly declare a size.

You got me there, I did leave ; off all those lines, but I made the change and I get the same error.

From the Arduino Arrays page:

Creating (Declaring) an Array

All of the methods below are valid ways to create (declare) an array. 

  int myInts[6];
  int myPins[] = {2, 4, 8, 3, 6};
  int mySensVals[6] = {2, 4, -8, 3, 2};
  char message[6] = "hello";



You can declare an array without initializing it as in myInts.

In myPins we declare an array without explicitly choosing a size. The compiler counts the elements and creates an array of the appropriate size. 


Finally you can both initialize and size your array, as in mySensVals. Note that when declaring an array of type char, one more element than your initialization is required, to hold the required null character.

And I'm pretty sure I don't have to assign values to an array one by one, correct? I can assign the entire array in one swift move like I did, right? I'll admit, it's been a couple months since I coded anything, especially involving arrays.

The Arduino arrays page said that the IDE automatically counts the number of elements being put into an array, so I don't have to explicitly declare a size.

But where does it say that you can assign arrays like that?

I've seen that very same implementation of array-assigning before.

I've seen that very same implementation of array-assigning before

Really?
For C/C++?

I can't find any examples because I don't know where I saw them precisely, but it was other code and/or libraries for sending data to shift registers for LED matrices.

How else am I supposed to do it, one bit at a time? There has to be a better way.

I've seen people draw out character sets in bits in an array, and then have them sent as such to the array.

So what am I thinking of, and how do I get there? I'd like to be able to just send a string of 1s and 0s to the chip and have it be done. I don't want to have to go like:

HC259_data[0] = 0;
HC259_data[1] = 1;
HC259_data[2] = 0;
HC259_data[3] = 1;
HC259_data[4] = 0;
HC259_data[5] = 1;
HC259_data[6] = 0;
HC259_data[7] = 1;

Because to me that's just idiotic and a waste of typing. There has to be an easier way of doing it, I have seen it used repeatedly.

And I'm sorry to be blunt here, but the way you're going about telling me I'm wrong is hurtful. You could have just said "No, you're wrong, that's not how you do it, please try this instead," but instead you're drawing this out and deliberately belittling me. I do not like it, and I refuse to be trolled.

I never claimed to be an expert at anything, that's why I came here asking for help, ok? I don't need the attitude. I'll gladly wait for somebody else to help me if this is how you're going to be.

I can't find any examples

.. because they don't exist.

You can initialise an array like that, but you can't assign.

Idiotic?
Maybe.

You could use direct port manipulation from a simple binary representation.

I will repeat myself:

And I'm sorry to be blunt here, but the way you're going about telling me I'm wrong is hurtful. You could have just said "No, you're wrong, that's not how you do it, please try this instead," but instead you're drawing this out and deliberately belittling me. I do not like it, and I refuse to be trolled.

I never claimed to be an expert at anything, that's why I came here asking for help, ok? I don't need the attitude. I'll gladly wait for somebody else to help me if this is how you're going to be.

Please offer me an alternative or direct me to where I can find out what I should be doing, or else stop pestering me and let somebody who will be civil answer my question. Way to make me feel welcome and supported.

Who's belittling?
You're telling me something that simply isn't true.
How am I supposed to feel?

Dash_Merc, It has to be said the IDE isn't clever about what the errors are, it doesn't often give a great deal of help. I have done similar things and I kick myself when I find them. Don't worry about them

As for AWOL being rude, well, it has to be said you have put across the same attitude to me. The 6 stars bellow your name don't make you some sort of God, it just means that if you are a troll you do it lots. God member is so misleading.

Idiotic?
Mabye

No, that's a lack of understanding of C/C++

As far as I know C# does the same thing too, and as C++ is the evolution of C then C++ is redundant. It falls into the same category. Just thought I should point that out.

If I'm telling you something that's not true, then call me out on it. Don't make me look like I'm more stupid than I am by drawing it out into a stupid game. How are you supposed to feel? I dunno, maybe like correcting the error of my ways, not aggravating the hell out of somebody asking for honest help and embarrassing them to no good end.

I never claimed to be right; I said that my experience told me I was right. I have done something similar before, and I have seen something similar done before, I just don't remember the exact implementation, and working off what I remember, that's what I arrived at.

I don't use arrays very often for most of what I do, because I just plain don't like them, and I rarely have a use for them.

I am not a genius coder, nor even a very experienced one, but I have done some big projects in PHP, and I have done lots of little learning assignment things in C/C++, so I thought I could claim to have some experience. Because I do. I'm not a complete newbie, I just have holes in my teachings because I'm completely self-taught.

I have taken classes and failed because they were confusing and I couldn't take the time I needed to explore a specific topic to the depth I felt like exploring it. Whole semesters and hundreds of dollars wasted. But when I spend a week or two studying something on my own and trying to make something work? I get it.

The only reason I came here asking what was wrong is so I could find out what was right and learn something new, not have it publicly rubbed in my face how wrong I am. It's not fair that I get treated this way when all I asked is how to fix it. All I want to do is to learn, ok? You can help me learn something new and receive my thanks and the satisfaction of knowing that there might be another person out there some day who can help people learn, or you can hinder me and waste everyone's time.

I have seen people define character sets for LED matrices in some way similar to this, but I don't remember where or what it's called, so I can't look it up:

E = {
1,1,1,1,1,
1,0,0,0,0,
1,1,1,0,0,
1,0,0,0,0,
1,1,1,1,1}

How do I do that? That is what I was trying to do, and I was almost positive it was done with arrays, but obviously I was wrong. What is right?

Thank you graymalkin. I'm sure I'll find what I'm looking for somewhere. And then, yes, I will surely kick myself for it. But I will learn, and that's what's important.

@graymalkin

As far as I know

But you thought TRUE was a C keyword and that assembler programming on PIC is easier than C, so yes, maybe I don't believe you either.

The 6 stars bellow[sic] your name don't make you some sort of God,

You're right, that's true, but I can count to five.

As far as I know C# does the same thing too, and as C++ is the evolution of C then C++ is redundant

Is this Non Sequitur Night?

What kind of satisfaction do you get from being a complete dick to everyone? Why is it the people with the experience sit on top of their mountains and laugh at those of us trying to climb them, rather than helping us?

AWOL, weren't you young once, too? Didn't you ever need mentorship or help of some kind? Did you ever have a passion for something and struggle against all odds and obstacles to learn it, despite not being naturally very good at it?

I've spent the last ten years teaching myself this **** because nobody else would take the time to teach me the way I needed to be taught. The few people who helped me along the way stand emblazoned in my memory as saints. I have made a lot of progress, considering I have been learning it completely on my own with almost no help at all from anybody. I don't need flak from assholes on the internet. I am passionate about what I do, and that's why I fight so hard to do it. Unless you're going to be helpful, kindly go away. Stop being a bully. Stop trying to make up for something you're not by belittling others. Go find something better to do with your time. Meanwhile, the rest of us will be helping one another grow and sharing in the joy that is learning.

Have fun being alone.

I've spent the last ten years teaching myself this **** because nobody else would take the time to teach me the way I needed to be taught.

And how are we supposed to know what way you need to be taught? There are plenty o C, C++, PHP, etc. books around that explain how arrays should be declared, initialized, and altered. Presumably, you are able to read.

The syntax you are trying to use is close to how you initialize an array on declaration. Once the array is declared, and initialized, the syntax for changing the value of an array requires that you change one element at a time.

We were all young at some point, and passionate about programming or electronics or both. Some of us struggled to learn to program. Others find it easy. But, being good at something does not necessarily translate into being a good teacher.

If you were taking a class that AWOL was teaching, I'm sure that you would find AWOL a decent teacher. Communicating on a forum is quite different from communicating in person, where you can see facial expressions or hear the mumbling and cursing of a person having trouble with something.

Often times, on the forum, hints are all that a person needs. Sometimes, the person needs more help. So, hints are offered, first. If that turns out not to be sufficient, more detail is provided, unless the OP turns out to be so thin skinned that they are insulted that the exact answer was not given in the first response.

We are trying to help. We don't know your background, so we don't always give you what you need on the first reply. When you come back, though, and say that you know you are right, when clearly (as the compiler is still complaining) you are not, the incentive to keep trying to help goes away.

First, I did not insist I was right. I insisted that I had seen something like that before.

Second, his first reply was quite cryptic as to the cause of the problem. He never once said "you can't add values to an array like that," until after he had embarrassed me and made me feel like an idiot. All he had to do was say "Dash, arrays don't work like that."

The fact that he highlighted the missing semicolon is the number one point of confusion. He did not indicate that I was doing it wrong, he indicated that my problem was a lack of semicolons.

If he had just said "you can't do that, read-up on the difference between declaring an array and adding value to it," then I would have understood his meaning and done the requisite re-reading, knowing specifically how my code was in error, and this conversation would be long over, and he would have received my thanks. His method of hinting was too soft. I thought "of course I forgot a semicolon" not "of course I'm using this array thing the wrong way."

I understand the need to get users to teach themselves by using hinting, but the way he went about it made me feel threatened, exposed, and targeted.

Also, I made it pretty apparent that I needed direction, and didn't receive it. I wanted to be pointed to an example of what I was thinking of, showing me how I was confused, or perhaps a link to a page explaining arrays, or maybe even a quote from the very sane array page I quoted, only from the part about adding values to an array.

Now that I know what's wrong, in specific, I will fix it. Thank you all for your guidance. I'm sorry I was oversensitive and didn't take your gentle prodding in the right way.

I apologise.
It was never my intention to belittle or embarrass.

In what I laughingly call my "spare-time", I teach another discipline.
Here, if the student (often people I have met just minutes before) doesn't follow rules or mis-hears something, s/he and I could both end up dead very quickly, so I make sure that both the student and I understand everything about what we about to do, what their abilities and limitations are, and then we review absolutely everything.

The best way I know of finding out what a student knows is to ask them, and also get them to question themselves as a means of reviewing things they really do know, but may have misplaced.

That's all I was trying to do, and again, I apologise if it came across as rude.

I recommend you to search about bit manipulation:
http://www.arduino.cc/playground/Code/BitMath

And search about it in google.

If you want to send 11111010 you would want a:
unsigned char myVar=0xFA;
Always use unsigned chars as they only take 8 bits, and an int takes you 16 bits and it is wasting precious space.

Thank you both.

I’m sorry for the misunderstanding, AWOL. I’m sorry I treated you like a troll. The way I reacted was uncalled for.

@Senso: thanks, I’ll look into it. It looks like it’ll be a big chunk to swallow, but some reading on the topic in between issues at work should get me where I need to be.

For now, my revised code just pre-defines separate arrays from the get-go and passes them to my send_data function to be broken down and applied to the correct bit registers on the 74HC259 chip as such:

boolean HC259_address[] = {0,0,0};
boolean HC259_data_1[] = {0,0,0,0,0,0,0,0};
boolean HC259_data_2[] = {1,0,1,0,1,0,1,0};
boolean HC259_data_3[] = {0,1,0,1,0,1,0,1};
boolean HC259_data_4[] = {1,1,1,1,1,1,1,1};

int HC259_A_pin = 4;
int HC259_B_pin = 3;
int HC259_C_pin = 2;
int HC259_data_pin = 5;

void setup()
{
  pinMode(HC259_A_pin, OUTPUT);
  pinMode(HC259_B_pin, OUTPUT);
  pinMode(HC259_C_pin, OUTPUT);
  pinMode(HC259_data_pin, OUTPUT);
}

void loop()
{
  HC259_send_data(HC259_data_1);
  delay(1000);
  HC259_send_data(HC259_data_2);
  delay(1000);
  HC259_send_data(HC259_data_3);
  delay(1000);
  HC259_send_data(HC259_data_4);
  delay(1000);
}

void HC259_send_data(boolean placeholder[])
{
  for (int i = 0; i <= 7; i ++)  // For each array element
  {
    HC259_set_address(i);
    digitalWrite(HC259_data_pin,placeholder[i]);
  }
}

void HC259_set_address(int latch)
{
  switch (latch)
  {
    case 0:
      HC259_address[0] = 0;
      HC259_address[1] = 0;
      HC259_address[2] = 0;
      break;
    case 1:
      HC259_address[0] = 0;
      HC259_address[1] = 0;
      HC259_address[2] = 1;
      break;
    case 2:
      HC259_address[0] = 0;
      HC259_address[1] = 1;
      HC259_address[2] = 0;
      break;
    case 3:
      HC259_address[0] = 0;
      HC259_address[1] = 1;
      HC259_address[2] = 1;
      break;
    case 4:
      HC259_address[0] = 1;
      HC259_address[1] = 0;
      HC259_address[2] = 0;
      break;
    case 5:
      HC259_address[0] = 1;
      HC259_address[1] = 0;
      HC259_address[2] = 1;
      break;
    case 6:
      HC259_address[0] = 1;
      HC259_address[1] = 1;
      HC259_address[2] = 0;
      break;
    case 7:
      HC259_address[0] = 1;
      HC259_address[1] = 1;
      HC259_address[2] = 1;
      break;
    default:
      // Do nothing
      int testint = 1;
  }
  digitalWrite(HC259_A_pin,HC259_address[0]);
  digitalWrite(HC259_B_pin,HC259_address[1]);
  digitalWrite(HC259_C_pin,HC259_address[2]);
}

I know there’s a more elegant way to do it…but right now I just want to make sure I understand how these chips work before I spend any more time massaging code for them.

The compiler doesn’t complain, and I don’t see any errors, but I have no way of knowing if it works yet, because I’m not able to test the code this second.