Anyone use an initialization loop?

Hey everyone,
So I'm working on a project that uses a common anode RGB LED (didn't know it was common anode till after the fact). So OUTPUT are initialized during setup as being 0. So when my loop starts the LED kicks on. What I've ended up doing is have a initialization while loop that just runs once and never runs again unless the Arduino is reset. It sets the RGB outputs to high right off the bat.

Is this a common practice? Just wondering if anyone else does that out there, if so any pointers? Also if anyone has a fix to my RGB LED being on right away (other than order common cathode, which I'm going to make sure for future runs of this project) it would be much appreciated. I mostly wanted to see if I was doing an obvious "no no" which I don't believe I am, but I know I can't be the only one that's had this issue before.

Is this a common practice?

Yes, when you acquire the wrong hardware.

if so any pointers?

char *thisIsAPointer;

You can put any code that you want to run once in setup(). That is exactly what it is there for. What I don't get is why you are using a while loop. While what ? Please post your code.

UKHeliBob:
You can put any code that you want to run once in setup(). That is exactly what it is there for. What I don't get is why you are using a while loop. While what ? Please post your code.

You learn something new every day. I didn't not realize "setup" would allow any code. I was pretty much going to duplicate it which now knowing that any code can be ran in setup, I feel.. well lets just say ignorant, which is being nice to myself. Thank Bob, that clears things up quite a bit.

PaulS:

Is this a common practice?

Yes, when you acquire the wrong hardware.

if so any pointers?

char *thisIsAPointer;
  1. Yeah, I know. I've never really dealt with RGB Led's so I wasn't aware of the common anode/cathode setup. It probably didn't help that the Amazon seller didn't even have it in their description. I was ass-uming they all were common cathode.

  2. Zing, you got me :slight_smile:

Is this a common practice? Just wondering if anyone else does that out there,

Does what ? (order hardware without reading the datasheet ? Sure, all the time. They wind up posting here just like you.