Im sure there is a better way to do this...

Is there a more efficient way to tell arduino to blink my LED 16 times?

Here's my code:

void loop() {

//Integer match operations//
if (orange > 11) {
byte (orange = 0);
}
if (orange >= 6) {
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (250);
digitalWrite(LED, 1);
delay (250);
digitalWrite(LED, 0);
delay (3000);
}

There would be less code if you used a for loop for the blinky part: http://arduino.cc/en/Reference/For

-br

byte (orange = 0);

The compiler won't complain, but it is a strange, pointless construct.

I notice that the variable orange is used on the first line in an if statement and then it seems like you are trying to declare a new local variable with the same name. That's a really bad idea. You should never use the same name for two variables if you can help it.

I'm not sure if those parenthesis that AWOL pointed out are stopping that from being a declaration or not.

It isn't a declaration.
It's an assignment, with a pointless cast of the result.

Where's the pre-setup and void setup() code?

I am using this to pour drinks. I want the arduino to keep track of how many ounces of each beverage it has poured, and alert me via a blinking light when one of the bottles becomes low on liquid. In this case, I want the light to blink 16 times (corresponding to bottle number 16, which holds the orange juice) when six or more ounces of orange juice has been poured- thus alerting me to the condition of the bottle. When i re-fill the bottle, I will touch a tactile switch which will reset the count of bottle 16 to zero. I have yet to implement anything about the reset switch... i'm getting there.

My entire code is long... but here is the gist:

Im using three shift registers to run my transistors leading to my pumps (23 pumps in total) so:

byte orange1st = 0x0;
byte orange2nd = 0x0;
byte orange3rd = 0x80;

then this byte is to keep count of ounces:

byte orange = 0;

then eventually this:

void loop()  {
  
 //Integer match operations//
if (orange > 11) {
      byte (orange = 0); 
}
if (orange >= 6) {
      digitalWrite(LED, 1);
   delay (250);
      digitalWrite(LED, 0);
   delay (250);
      digitalWrite(LED, 1);
   delay (250);
      digitalWrite(LED, 0);
   delay (250);
      digitalWrite(LED, 1);
   delay (250);
      digitalWrite(LED, 0);

etc, etc, etc,... until it blinks 16 times

Further down in the code, this happens:

if (packBuff[0]== 'A' && packBuff[1]=='M' && packBuff[2]=='K' && packBuff[3]=='A') // If the message sent from my iphone = "AMKA", then run the following script, which pours orange juice for 3 seconds. 
{

  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, orange1st); 
  shiftOut(data, clock, MSBFIRST, orange2nd);
  shiftOut(data, clock, MSBFIRST, orange3rd);
  digitalWrite(latch, 1);
  byte (orange = orange + 3);
  Serial.print("orange juice has now pumped ");
  Serial.print(orange);
  Serial.println(" ounces.");
       
    }
  delay(3000);

Thus, it pours my orange juice for 3 seconds (which, for simplicities sake I am saying equals 3 ounces for right now) The arduino then adds 3 to my count of ounces of orange juice poured. As the program loops back to the code earlier, it reads the orange integer again. If it is greater than or equal to six ounces- it begins to warn me via the blinking light. At this point, the code

if (orange > 11) {
      byte (orange = 0); 
}

Is standing in for my tactile reset button. It is helping me test that theory is all.

I was just looking for a less intensive way to blink the warning light a certain number of times. As you can guess- with 24 bottles, blinking the light the way I am currently doing it will end up ridiculously long-winded. I'll look into the for loop mentioned!

Why not add a 4 digit seven segment display, directly show the number & quantity, have that flash to get your attention.
Use SPI to drive MAX7219 to drive up to 8 digits, get some meaningful info.
Or a serial interface LCD display even, such as:

byte (orange = 0);

My guess is that the brackets eliminated a previous compile error about redeclaration of a variable.

Throwing bits of punctuation and brackets at your code to get it to pass through the compiler, is a sure way to some serious head scratching down the road when things aren't working.

I know, lessons learned the hard way.

Why not add a 4 digit seven segment display, directly show the number & quantity, have that flash to get your attention.

Haha- baby steps, good Sir. Baby steps. This is my very first soiree into electronics or code writing AT ALL- and I am taking on an ambitious project here. I started not even a month ago with my "hello world" LED, and I am already successfully controlling 23 pumps through 3 shift registers over wifi from an ipad app. If there is anything I have learned yet- it's to keep the end goal in sight, but only tackle one mystery at a time. I'll start with the LED (it's just so darn simple!) and maybe work my way up to an LCD display once my laundry list of existing hurdles is dwindling. Thanks for the suggestion though- it's a great idea! More info is always better!

My guess is that the brackets eliminated a previous compile error about redeclaration of a variable.

oh. no... I just was under the impression they needed to be there? I slapped them on there right from the get-go. I'll try it without them!

And without the word byte. Leaving that byte in there will certainly bite you in the butt since it will leave you with two variables with the same name.

So, i tried it without the parenthsis around my byte declarations, and it still compiled just fine- but it stopped doing any math… it would no longer add three each time, or reduce it back to zero when it went over 11. So, I put the parenthesis back? As soon as I did, It began doing the intended math again. Maybe I misunderstood…

Also- I read that article about for loops and I am maybe not yet fully grasping it.

I have

if (orange >= 6) {                     //am I running low on OJ?  If so,
  for (int x = 0; x < 17; x++){     //then blink my LED x number of times

//statement goes here that uses "x" to know how many times to blink my LED

}
delay (3000);                          //...and pause between sets of blinks

but NOW what? what statement do I tie to “x” that will blink my LED “x” number of times with a 250 delay in between blinks?

for (int x = 0; x < 17; x++){

That will give you 17 flashes - I thought you wanted 16?

So, i tried it without the parenthsis around my byte declarations, and it still compiled just fine- but it stopped doing any math.

Post your code

but NOW what? what statement do I tie to “x” that will blink my LED “x” number of times

The code to do ONE flash

And without the word byte.

Ahhh… I see what you are saying! I am creating multiple bytes with the exact same name! Thanks! I fixed that, works perfectly.

That will give you 17 flashes - I thought you wanted 16?

uh, yeah I do… my maths are weaksauce. I thought that since it was set to less than 17 that it would stop at 16… but I suppose 0 counts too eh?

The code to do ONE flash

ok- so

if (orange >= 6) {                     //am I running low on OJ?  If so,
  for (int x = 0; x < 16; x++){     //then blink my LED x number of times

      digitalWrite(LED, 1);
   delay (250);
      digitalWrite(LED, 0);
   delay (250);

}
delay (3000);                          //...and pause between sets of blinks

I don’t see how that uses “x” ?

EDIT: fixed my math in the code lol

It uses x to count how many times to do one flash.
And yes, 0…16 is seventeen times, so “x < 16” is the correct comparison here.

FANTASTIC! Works like a charm

Not only am I walking out of this thread with the answer I was looking for originally, but I learned a valuable lesson about declaring same-named byte values, I understand this for loop business much better- and my code works!

Thanks again guys!