Structures??

I'm going to show everyone just how much I don't know here.

Years ago I used to do some PLM coding for embedded applications. We would set up a structure using the 'dot' operator. For instance the definition would be:

define timer is (
start_count byte
timed_out boolean
counter byte);

then the instance would be:
general_timer type timer;

Then the usage would be:
general_timer.start_timer = 0;
general_timer.timed_out = false;
if (general_timer.counter > 1) then
begin
.....
end;
.
.
. etc.

I may have some of that wrong since it was a BUNCH of years ago but hopefully you get the point.

My question is, can I do the same type thing with Arduino?? and how?

Russ

My question is, can I do the same type thing with Arduino??

Yes.

and how?

struct or class. The only difference is the default access. Start with struct.

typedef struct
{
  byte start_count;
  boolean timed_out;
  byte counter;
}
timer_t;

timer_t general_timer;

general_timer.start_count = 0;
general_timer.timed_out = false;
if (general_timer.counter > 1) 
{
  .....
}

Thanks very much! It looks like the idea is exactly the same, just the syntax is a little different.

I found the 'struct' definition in the playground thingy. However, I couldn't find one for 'typedef'. I've seen that used in several places but don't know what it means. Is it required?

I'm finding that if I keep things elementary simple then I tend to not get confused as much. This C stuff is really cryptic.

I use my Arduino to control the temperatures in my two smokers during BBQ competitions. I absolutely LOVE showing my homemade controller to the guys who paid hundreds of $ for theirs. ;D

Russ

However, I couldn't find one for 'typedef'.

typedef simply introduces a new type.

If you just define a structure:

struct myStruct {//blah};

then every time you want a "myStruct", you have to tell the compiler it's a "struct":

struct myStruct myInstance;

However:

typeded struct {//blah} myStruct;

allows you to write:

myStruct myInstance;

This C stuff is really cryptic.

Let me show you some APL sometime ;D