Too many "if" statements?

So, my project code is sitting at about 18,000 bytes size-wise (so plenty of space left), and my arduino is acting strangely whenever I attempt to add one more "if".

I have a bunch of "if" statements in a row. They are nested inside one "if", and after that they are independent of one another.

So basically (in a very simplistic example):

1.if
a. if
b. if
c. if
d. if
e. if

...and so on and so forth for a long time.

Everything works fine until I add ONE MORE... then nothing works fine at all. Can the arduino only handle so many "if" statements before it goes batty? (more specifically, by "batty" i mean it ceases to run code that runs just fine as long as I delete any other "if" statement, and sometimes it freezes in the middle of an operation and needs to be reset)

Guessing, but that sounds like you're out of RAM.

Jim_Socks:
Can the arduino only handle so many "if" statements before it goes batty?

That is very unlikely to be a problem.

I agree with @wildbill.

Sounds entirely plausible.

Any ways to alleviate this problem? I don't suppose I could add more could I? Does the Mega have more RAM than an Uno perhaps? Or maybe there are some nifty code tricks I could read up on to minimize my RAM usage?

There are usually ways to reduce your usage, unless you've already been extremely frugal. Post your code.

IF the if's are nested it might also be that the compiler has some internal stack overflow.

Please post your code +1

The Mega does indeed have more RAM than the Uno - 8k vs 2k, so if necessary, you can solve the problem by throwing money at it.

I am really new to coding, and arduino in general- so while I would like to THINK I have been frugal, I am sure my efforts are laughable. It doesn’t help that my project is VERY big…

My code is long as Hell. Give me a few minutes to post it all…

#include <SPI.h>         // for Arduino later than ver 0018
#include <EthernetUdp.h>   // UDP library from bjoern@cs.stanford.edu
#include <Ethernet.h>

                       
//////////  NETWORK INFO  ////////////////

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xDB, 0x50 };  //Set your Ethernet Shield's MAC address here - make sure you replace the ZZs with your shield's values!
byte ip[] = { 192, 168, 0, 9 };    // Set your shield's desired IP address here - check your network for configuration detail
unsigned int localPort = 7777;      // local port to listen on (set this the same as Port # on Ardumote Params Screen)
IPAddress iPhoneIP(192, 168, 0, 4);  //Set the iPhone/iPod/iPad's IP address to send messages back to Ardumote...
unsigned int iPhonePort = 7777;      //Set the Port # of the message table you configured in Ardumote (default is 7777)...


///////// Pin Assignments /////////////////


int data = 6;     //Begin Shift register integers
int clock = 7;
int latch = 8;
int LED = 9;
int ledState = 0;

const int ON = HIGH;
const int OFF = LOW;   //end shift register integers

//begin drink integers

byte vodka1st = 0x1;
byte vodka2nd = 0x0;
byte vodka3rd = 0x0;
byte rumlt1st = 0x2;
byte rumlt2nd = 0x0;
byte rumlt3rd = 0x0;
byte rumdk1st = 0x4;
byte rumdk2nd = 0x0;
byte rumdk3rd = 0x0;
byte whiskey1st = 0x8;
byte whiskey2nd = 0x0;
byte whiskey3rd = 0x0;
byte gin1st = 0x10;
byte gin2nd = 0x0;
byte gin3rd = 0x0;
byte brandy1st = 0x0;
byte brandy2nd = 0x2;
byte brandy3rd = 0x2;
byte tequila1st = 0x4;
byte tequila2nd = 0x0;
byte tequila3rd = 0x0;
byte amarretto1st = 0x20;
byte amarretto2nd = 0x0;
byte amarretto3rd = 0x0;
byte kahlua1st = 0x80;
byte kahlua2nd = 0x0;
byte kahlua3rd = 0x0;
byte midori1st = 0x0;
byte midori2nd = 0x1;
byte midori3rd = 0x1;
byte tripsec1st = 0x40;
byte tripsec2nd = 0x0;
byte tripsec3rd = 0x0;
byte vermouth1st = 0x0;
byte vermouth2nd = 0x4;
byte vermouth3rd = 0x4;

byte sour1st = 0x0;
byte sour2nd = 0x10;
byte sour3rd = 0x10;
byte grenad1st = 0x0;
byte grenad2nd = 0x80;
byte grenad3rd = 0x0;
byte syrup1st = 0;
byte syrup2nd = 0;
byte syrup3rd = 0;

byte cran1st = 0x0;
byte cran2nd = 0x8;
byte cran3rd = 0x8;
byte orange1st = 0x0;
byte orange2nd = 0x0;
byte orange3rd = 0x80;
byte pine1st = 0;
byte pine2nd = 0;
byte pine3rd = 0;

byte cola1st = 0x0;
byte cola2nd = 0x20;
byte cola3rd = 0x20;
byte sprite1st = 0;
byte sprite2nd = 0;
byte sprite3rd = 0;
byte tonic1st = 0x0;
byte tonic2nd = 0x40;
byte tonic3rd = 0x40;
byte ginger1st = 0;
byte ginger2nd = 0;
byte ginger3rd = 0;

byte water1st = 0;
byte water2nd = 0;
byte water3rd = 0;

byte motorsoff = 0x0;

// BEGIN WARNING LIGHT INTEGERS

byte vodka = 0;
byte rumlt = 0;
byte rumdk = 0;
byte whiskey = 0;
byte gin = 0;
byte brandy = 0;
byte tequila = 0;
byte amarretto = 0;
byte kahlua = 0;
byte midori = 0;
byte tripsec = 0;
byte vermouth = 0;

byte sour = 0;
byte grenad = 0;
byte syrup = 0;

byte cran = 0;
byte orange = 0;
byte pine = 0;

byte cola = 0;
byte sprite = 0;
byte tonic = 0;
byte ginger = 0;

byte water = 0;

// Time integers
int d = 375;
int q = 750;
int th = 1000;
int h = 1500;
int tq = 2250;
int o = 3000;
int oh = 4500;
int t = 6000;
int warn = 3000;




///////////////// UDP Variables  ////////////////// 

// buffers for receiving and sending data
char packBuff[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

/////////////////////////////////////////////////



EthernetUDP Udp;

void setup()  {
  //start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);  // Setup UDP on port defined earlier
  Serial.begin(9600);    // Start serial com @ 9600 bps (baud)
    
    //  set pins for shift register
  pinMode(data, OUTPUT);  //begin shift register pinmodes
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
  pinMode(LED, OUTPUT);

  digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, motorsoff);  
  shiftOut(data, clock, MSBFIRST, motorsoff); 
  digitalWrite(latch, 1);

  
}

void loop()  {
  

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////// W A R N I N G  L I G H T S ///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
delay (100);
 
 ////////////////////////////////////////  V O D K A
 
    if (vodka > 190) {
      vodka = 0; 
}
if (vodka >= 180) {
 for (int x = 0; x < 1; x++){
    
     flash();
 }
   delay(warn);
    }
 
  ////////////////////////////////////////  L I G H T  R U M
 
     if (rumlt > 190) {
      rumlt = 0; 
}
if (rumlt >= 180) {
 for (int x = 0; x < 2; x++){
    
     flash();
 }
   delay(warn);
    }
 
 ////////////////////////////////////////  D A R K  R U M
 
    if (rumdk > 190) {
      rumdk = 0; 
}
if (rumdk >= 180) {
 for (int x = 0; x < 3; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  W H I S K E Y
 
    if (whiskey > 190) {
      whiskey = 0; 
}
if (whiskey >= 180) {
 for (int x = 0; x < 4; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  G I N
 
    if (gin > 190) {
      gin = 0; 
}
if (gin >= 180) {
 for (int x = 0; x < 5; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  B R A N D Y
 
    if (brandy > 190) {
      brandy = 0; 
}
if (brandy >= 180) {
 for (int x = 0; x < 6; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  T E Q U I L A
 
    if (tequila > 190) {
      tequila = 0; 
}
if (tequila >= 180) {
 for (int x = 0; x < 7; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  A M A R E T T O
 
    if (amarretto > 190) {
      amarretto = 0; 
}
if (amarretto >= 180) {
 for (int x = 0; x < 8; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  K A H L U A
 
    if (kahlua > 190) {
      kahlua = 0; 
}
if (kahlua >= 180) {
 for (int x = 0; x < 9; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  M I D O R I
 
    if (midori > 190) {
      midori = 0; 
}
if (midori >= 180) {
 for (int x = 0; x < 10; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  T R I P L E  S E C
 
    if (tripsec > 190) {
      tripsec = 0; 
}
if (tripsec >= 180) {
 for (int x = 0; x < 11; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  D R Y  V E R M O U T H
 
    if (vermouth > 190) {
      vermouth = 0; 
}
if (vermouth >= 180) {
 for (int x = 0; x < 12; x++){
    
     flash();
 }
   delay(warn);
    }
    
  ////////////////////////////////////////  S O U R  M I X
 
    if (sour > 190) {
      sour = 0; 
}
if (sour >= 180) {
 for (int x = 0; x < 13; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  G R E N A D I N E
 
    if (grenad > 190) {
      grenad = 0; 
}
if (grenad >= 180) {
 for (int x = 0; x < 14; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  S I M P L E  S Y R U P
 
    if (syrup > 190) {
      syrup = 0; 
}
if (syrup >= 180) {
 for (int x = 0; x < 15; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  C R A N B E R R Y  J U I C E
 
    if (cran > 190) {
      cran = 0; 
}
if (cran >= 180) {
 for (int x = 0; x < 16; x++){
    
     flash();
 }
   delay(warn);
    }
  ////////////////////////////////////////  O R A N G E  J U I C E
 
    if (orange > 190) {
      orange = 0; 
}
if (orange >= 180) {
 for (int x = 0; x < 17; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  P I N E A P P L E  J U I C E
 
    if (pine > 190) {
      pine = 0; 
}
if (pine >= 180) {
 for (int x = 0; x < 18; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  C O L A
 
    if (cola > 190) {
      cola = 0; 
}
if (cola >= 180) {
 for (int x = 0; x < 19; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  S P R I T E
 
    if (sprite > 190) {
      sprite = 0; 
}
if (sprite >= 180) {
 for (int x = 0; x < 20; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  T O N I C
 
    if (tonic > 190) {
      tonic = 0; 
}
if (tonic >= 180) {
 for (int x = 0; x < 21; x++){
    
     flash();
 }
   delay(warn);
    }
    
   ////////////////////////////////////////  G I N G E R  A L E
 
    if (ginger > 190) {
      ginger = 0; 
}
if (ginger >= 180) {
 for (int x = 0; x < 22; x++){
    
     flash();
 }
   delay(warn);
    }
   ////////////////////////////////////////  W A T E R
 
    if (water > 190) {
      water = 0; 
}
if (water >= 180) {
 for (int x = 0; x < 24; x++){
    
     flash();
 }
   delay(warn);
    }
 
    
 
 
  //  the following looks for a packet and then reads it and prints it after subtracting 8
  int packetSize = Udp.parsePacket();  //  note that this includes the UDP header
  if(packetSize)  {               //if a packet is there...
    packetSize = packetSize - 8;  //subtract the 8 byte header
    Serial.print("Packet size: ");
    Serial.println(packetSize);  //  ... and then print it to the monitor
    
              //  the following will read the packet into packetBuffer and get the senders IP addr and port number
    Udp.read(packBuff,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Message: ");
    Serial.println(packBuff);
    
    
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// O L D  F A S H I O N E D  G L A S S ////////////////////////////////////////////////////////
///////////////////////////////////////////// N O N - P E R I S H A B L E ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 delay (100); 
//////////////////////// 1. Amaretto Mist (lime wedge) /////////////////////////////////////

if (packBuff[0]== 'A' && packBuff[1]=='M' && packBuff[2]=='O' && packBuff[3]=='N') 
{

amaretto15(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Amaretto Mist- Serve with a lime wedge.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
  
  
  //////////////////////// 1. Black Cat /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='L' && packBuff[2]=='O' && packBuff[3]=='N') 
{

amaretto15(); tequila15(); End();
  
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Black Cat.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Black Russian /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='2' && packBuff[2]=='O' && packBuff[3]=='N') 
{

vodka15(); kahlua75(); End();
   
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Black Russian.  Na zda-ro-vye!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
   //////////////////////// 1. Bonbon /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='O' && packBuff[2]=='O' && packBuff[3]=='N') 
{

tequila15(); trip15(); grenad25(); End();
   
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Bonbon.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
   //////////////////////// 1. Brantini (lemon twist) /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='R' && packBuff[2]=='O' && packBuff[3]=='N') 
{

gin1(); brandy15(); dryv25(); End();
   
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Brantini- Serve with a lemon twist. Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
    //////////////////////// 1. Brave Bull (lemon twist) /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='3' && packBuff[2]=='O' && packBuff[3]=='N') 
{

 tequila15(); kahlua1(); End();
   
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Brave Bull- Serve with a lemon twist.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
    //////////////////////// 1. Dead Hand /////////////////////////////////////

if (packBuff[0]== 'D' && packBuff[1]=='H' && packBuff[2]=='O' && packBuff[3]=='N') 
{

 midori2(); rumlt1(); vodka1(); whiskey1(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Dead Hand.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
    //////////////////////// 1. Dirty Mother /////////////////////////////////////

if (packBuff[0]== 'D' && packBuff[1]=='I' && packBuff[2]=='O' && packBuff[3]=='N') 
{

brandy15(); kahlua5(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Dirty Mother.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
    //////////////////////// 1. Ferrari (lemon twist) /////////////////////////////////////

if (packBuff[0]== 'F' && packBuff[1]=='E' && packBuff[2]=='O' && packBuff[3]=='N') 
{

amaretto1(); dryv15(); dryv5(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Ferrari- Serve with a lemon twist.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Flying Dutchman /////////////////////////////////////

if (packBuff[0]== 'F' && packBuff[1]=='L' && packBuff[2]=='O' && packBuff[3]=='N') 
{

trip5(); gin2(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Flying Dutchman.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
    //////////////////////// 1. Godmother /////////////////////////////////////

if (packBuff[0]== 'G' && packBuff[1]=='O' && packBuff[2]=='O' && packBuff[3]=='N') 
{

vodka15(); amaretto75(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Godmother.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
    //////////////////////// 1. Three Buffaloes /////////////////////////////////////

if (packBuff[0]== 'T' && packBuff[1]=='H' && packBuff[2]=='O' && packBuff[3]=='N') 
{

rumlt1(); tequila1(); whiskey1(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Three Buffaloes.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
    //////////////////////// 1.Vodka on the rocks (lemon twist)  /////////////////////////////////////

if (packBuff[0]== 'V' && packBuff[1]=='O' && packBuff[2]=='O' && packBuff[3]=='N') 
{

vodka2(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Vodka on the rocks- Serve with a lemon twist.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}

    
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// H I G H B A L L  G L A S S /////////////////////////////////////////////////////////////
///////////////////////////////////////////// N O N - P E R I S H A B L E ////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
delay (100);
 
    //////////////////////// 1. Golden Panther (1/2 an orange gets strained into this drink?) /////////////////////////////////////

if (packBuff[0]== 'G' && packBuff[1]=='O' && packBuff[2]=='H' && packBuff[3]=='N') 
{

	brandy33(); gin33(); whiskey33(); dryv33(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Golden Panther- strain 1/2 an orange in?.  Enjoy!?");    // Send Message back to iPhone
      Udp.endPacket();
    
}
 
    //////////////////////// 1. Mob Movie /////////////////////////////////////

if (packBuff[0]== 'M' && packBuff[1]=='O' && packBuff[2]=='H' && packBuff[3]=='N') 
{

kahlua15(); vodka15(); amaretto1(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Mob Movie.  Enjoy- or sleep with da fishes!!!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
    //////////////////////// 1. Beachside Martini (2-3 olives.  ) /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='E' && packBuff[2]=='M' && packBuff[3]=='N') 
{

dryv1(); vodka15(); vodka15(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Beachside Martini- Serve with olives.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
   
    //////////////////////// 1. Black Dog (pitted black olive) /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='L' && packBuff[2]=='M' && packBuff[3]=='N') 
{

rumlt15(); rumlt15(); dryv1(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Black Dog- Serve with a black olive.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Buckeye Martini (black olive) /////////////////////////////////////

if (packBuff[0]== 'B' && packBuff[1]=='U' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin15(); gin15(); dryv5(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Buckeye Martini- Serve with a black olive.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Cuban Martini (glass rimmed with sugar, lime twist) /////////////////////////////////////
/*
if (packBuff[0]== 'C' && packBuff[1]=='U' && packBuff[2]=='M' && packBuff[3]=='N') 
{

rumlt15(); rumlt15(); dryv5(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Cuban Martini- Serve in sugar-rimmed glass, lime twist.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Desert Martini (dip toothpick in dry vermouth and stir, or look at the bottle.  Driest martini in the world) /////////////////////////////////////
*/

if (packBuff[0]== 'D' && packBuff[1]=='E' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin2(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Desert Martini- Driest martini on Earth.  Mmm!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Dry martini (twist of lemon peel or olive) /////////////////////////////////////
/*
if (packBuff[0]== 'D' && packBuff[1]=='R' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin1(); gin33(); dryv33(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Dry martini- Serve with a lemon twist or olive.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Dusty Martini (glass rimmed with scotch. twist of lemon) /////////////////////////////////////

if (packBuff[0]== 'D' && packBuff[1]=='U' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin2(); dryvdash(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Dusty Martini- Serve in a scotch-rimmed glass w/lemon twist.");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Exotica Martini (lemon zest) /////////////////////////////////////

if (packBuff[0]== 'E' && packBuff[1]=='X' && packBuff[2]=='M' && packBuff[3]=='N') 
{

vodka1(); vodka25(); midori1(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Exotica Martini- Serve with lemon zest.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Fifty-Fifty martini (olive) /////////////////////////////////////

if (packBuff[0]== 'F' && packBuff[1]=='I' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin15(); dryv15(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Fifty-Fifty martini- Serve with olives.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Gent of the Jury (3 cocktail onions) /////////////////////////////////////

if (packBuff[0]== 'G' && packBuff[1]=='E' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin2(); dryv25(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Gent of the Jury- Serve with 3 cocktail onions. I said good day Sir!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Gibson (3 cocktail onions) /////////////////////////////////////

if (packBuff[0]== 'G' && packBuff[1]=='I' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin2(); gin2(); dryv5(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Gibson- Serve with 3 cocktail onions.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Great Caesar’s Martini /////////////////////////////////////

if (packBuff[0]== 'G' && packBuff[1]=='R' && packBuff[2]=='M' && packBuff[3]=='N') 
{

vodka15(); vodka15(); dryv5(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Great Caesar’s Martini. Fancy name for a vodka martini- Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Green Fantasy (kiwi slices) /////////////////////////////////////

if (packBuff[0]== 'G' && packBuff[1]=='2' && packBuff[2]=='M' && packBuff[3]=='N') 
{

dryv1(); midori1(); vodka1(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Green Fantasy- Serve with kiwi slices.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Honeydew Martini (lemon twist) /////////////////////////////////////

if (packBuff[0]== 'H' && packBuff[1]=='O' && packBuff[2]=='M' && packBuff[3]=='N') 
{

vodka15(); vodka15(); midori5(); trip5(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Honeydew Martini- Serve with a lemon twist.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. In and Out martini (swish vermouth and discard.  2 blue cheese stuffed olives and lemon twist) /////////////////////////////////////

if (packBuff[0]== 'I' && packBuff[1]=='N' && packBuff[2]=='M' && packBuff[3]=='N') 
{

      dryvdash(); End();

      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("You have 15secs to swish & discard the vermouth, then replace glass");    // Send Message back to iPhone
      Udp.endPacket();
      
      delay(15000); End();
      
      vodka2(); vodka15();
      
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("In and Out Martini- Serve with blu-cheese olives.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Klingon koffee (on rocks) /////////////////////////////////////

if (packBuff[0]== 'K' && packBuff[1]=='L' && packBuff[2]=='M' && packBuff[3]=='N') 
{

kahlua15(); vodka15(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Klingon koffee- Serve on the rocks.  I know... too late!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Martini Shawn Style (swish vermouth and discard.  Several olives on the side) /////////////////////////////////////

if (packBuff[0]== 'M' && packBuff[1]=='A' && packBuff[2]=='M' && packBuff[3]=='N') 
{

dryvdash(); End();
       
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("You have 15secs to swish & discard the vermouth, then replace glass");    // Send Message back to iPhone
      Udp.endPacket();
      
      delay(15000);
      
gin2(); gin15(); End();
      
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Martini Shawn Style- Olives on the side.  Hell YEAH!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Martini DRY (olives) /////////////////////////////////////

if (packBuff[0]== 'M' && packBuff[1]=='2' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin1();  gin33(); gin33(); dryv33(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Martini DRY- Serve with olives.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
  
    //////////////////////// 1. Martini 2-to-1 traditional (lemon twist or olive) /////////////////////////////////////

if (packBuff[0]== 'M' && packBuff[1]=='3' && packBuff[2]=='M' && packBuff[3]=='N') 
{

gin15(); dryv75(); End();
 
      Udp.beginPacket(iPhoneIP,iPhonePort);
      Udp.write("Martini 2-to-1 traditional- Serve with a lemon twist or olive.  Enjoy!");    // Send Message back to iPhone
      Udp.endPacket();
    
}
/////////////////////////////////////////////////// E N D E R /////////////////////////////////////////////////////////

void End()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock, MSBFIRST, motorsoff);  
  shiftOut(data, clock, MSBFIRST, motorsoff); 
  shiftOut(data, clock, MSBFIRST, motorsoff); 
  digitalWrite(latch, 1);
  delay(20);
}


/////////////////////////////////////////////////// V O D K A /////////////////////////////////////////////////////////
void vodkacount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, vodka1st); 
  shiftOut(data, clock, MSBFIRST, vodka2nd);
  shiftOut(data, clock, MSBFIRST, vodka3rd);
  digitalWrite(latch, 1); 
  Serial.print("Vodka has now pumped ");
  Serial.print(vodka);
  Serial.print(" quarter ounces, or around ");
  Serial.print(vodka / 4);
  Serial.println(" full ounces.");
}
void vodka25()
{
  vodka = vodka + 1;
  vodkacount();
  delay(q);
}
void vodka5()
{
  vodka = vodka + 2;
    vodkacount();  
  delay(h);
}
void vodka1()
{
  vodka = vodka + 4;
  vodkacount();  
  delay(o);
}
void vodka15()
{
  vodka = vodka + 6;
  vodkacount();  
  delay(oh);
}
void vodka2()
{

  vodka = vodka + 8;
  vodkacount();  
  delay(t);
}
/////////////////////////////////////////////////// L I G H T  R U M /////////////////////////////////////////////////////////
void rumltcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, rumlt1st); 
  shiftOut(data, clock, MSBFIRST, rumlt2nd);
  shiftOut(data, clock, MSBFIRST, rumlt3rd);
  digitalWrite(latch, 1); 
  Serial.print("Light Rum has now pumped ");
  Serial.print(rumlt);
  Serial.print(" quarter ounces, or around ");
  Serial.print(rumlt / 4);
  Serial.println(" full ounces."); 
}
void rumlt5()
{
  rumlt = rumlt + 2;
  rumltcount();
  delay(h);
}
void rumlt1()
{
  rumlt = rumlt + 4;
  rumltcount();  
  delay(o);
}
void rumlt15()
{
  rumlt = rumlt + 6;
  rumltcount();  
  delay(oh);
}
/////////////////////////////////////////////////// D A R K  R U M /////////////////////////////////////////////////////////
void rumdkcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, rumdk1st); 
  shiftOut(data, clock, MSBFIRST, rumdk2nd);
  shiftOut(data, clock, MSBFIRST, rumdk3rd);
  digitalWrite(latch, 1);
  Serial.print("Dark Rum has now pumped ");
  Serial.print(rumdk);
  Serial.print(" quarter ounces, or around ");
  Serial.print(rumdk / 4);
  Serial.println(" full ounces.");   
}
void rumdk5()
{
  rumdk = rumdk + 2;
  rumdkcount();
  delay(h);
}
void rumdk1()
{
  rumdk = rumdk + 4;
  rumdkcount();  
  delay(o);
}
void rumdk15()
{
  rumdk = rumdk + 6;
  rumdkcount();  
  delay(oh);
}
/////////////////////////////////////////////////// W H I S K E Y /////////////////////////////////////////////////////////
void whiskeycount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, whiskey1st); 
  shiftOut(data, clock, MSBFIRST, whiskey2nd);
  shiftOut(data, clock, MSBFIRST, whiskey3rd);
  digitalWrite(latch, 1);  
  Serial.print("Whiskey has now pumped ");
  Serial.print(whiskey);
  Serial.print(" quarter ounces, or around ");
  Serial.print(whiskey / 4);
  Serial.println(" full ounces.");   
}
void whiskey33()
{
  whiskey = whiskey + 2;
  whiskeycount();
  delay(th);
}
void whiskey5()
{
  whiskey = whiskey + 2;
  whiskeycount(); 
  delay(h);
}
void whiskey1()
{
  whiskey = whiskey + 4;
  whiskeycount();  
  delay(o);
}
void whiskey15()
{
  whiskey = whiskey + 6;
  whiskeycount();  
  delay(oh);
}

/////////////////////////////////////////////////// G I N /////////////////////////////////////////////////////////
void gincount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, gin1st); 
  shiftOut(data, clock, MSBFIRST, gin2nd);
  shiftOut(data, clock, MSBFIRST, gin3rd);
  digitalWrite(latch, 1);  
  Serial.print("Gin has now pumped ");
  Serial.print(gin);
  Serial.print(" quarter ounces, or around ");
  Serial.print(gin / 4);
  Serial.println(" full ounces.");  
}
void gin33()
{
  gin = gin + 2;
  gincount();
  delay(th);
}
void gin5()
{
  gin = gin + 2;
  gincount();  
  delay(h);
}
void gin1()
{
  gin = gin + 4;
  gincount();  
  delay(o);
}
void gin15()
{
  gin = gin + 6;
  gincount();  
  delay(oh);
}
void gin2()
{
  gin = gin + 8;
  gincount();  
  delay(t);
}
/////////////////////////////////////////////////// B R A N D Y /////////////////////////////////////////////////////////
void brandycount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, brandy1st); 
  shiftOut(data, clock, MSBFIRST, brandy2nd);
  shiftOut(data, clock, MSBFIRST, brandy3rd);
  digitalWrite(latch, 1); 
  Serial.print("Brandy has now pumped ");
  Serial.print(brandy);
  Serial.print(" quarter ounces, or around ");
  Serial.print(brandy / 4);
  Serial.println(" full ounces."); 
}
void brandy33()
{
  brandy = brandy + 2;
  brandycount();
  delay(th);
}
void brandy5()
{
  brandy = brandy + 2;
  brandycount();
  delay(h);
}
void brandy1()
{
  brandy = brandy + 4;
  brandycount();  
  delay(o);
}
void brandy15()
{
  brandy = brandy + 6;
  brandycount();  
  delay(oh);
}
/////////////////////////////////////////////////// T E Q U I L A /////////////////////////////////////////////////////////
void tequilacount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, tequila1st); 
  shiftOut(data, clock, MSBFIRST, tequila2nd);
  shiftOut(data, clock, MSBFIRST, tequila3rd);
  digitalWrite(latch, 1);  
  Serial.print("Tequila has now pumped ");
  Serial.print(tequila);
  Serial.print(" quarter ounces, or around ");
  Serial.print(tequila / 4);
  Serial.println(" full ounces."); 
}
void tequila5()
{
  tequila = tequila + 2;
  tequilacount();
  delay(h);
}
void tequila1()
{
  tequila = tequila + 4;
  tequilacount(); 
  delay(o);
}
void tequila15()
{
  tequila = tequila + 6;
  tequilacount();  
  delay(oh);
}
/////////////////////////////////////////////////// A M A R E T T O /////////////////////////////////////////////////////////
void amarettocount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, amarretto1st); 
  shiftOut(data, clock, MSBFIRST, amarretto2nd);
  shiftOut(data, clock, MSBFIRST, amarretto3rd);
  digitalWrite(latch, 1);  
  Serial.print("Amaretto has now pumped ");
  Serial.print(amarretto);
  Serial.print(" quarter ounces, or around ");
  Serial.print(amarretto / 4);
  Serial.println(" full ounces.");   
}
void amaretto5()
{
  amarretto = amarretto + 2;
  amarettocount();
  delay(h);
}
void amaretto75()
{
  amarretto = amarretto + 3;
  amarettocount();  
  delay(tq);
}
void amaretto1()
{
  amarretto = amarretto + 4;
  amarettocount();;  
  delay(o);
}
void amaretto15()
{
  amarretto = amarretto + 6;
  amarettocount(); 
  delay(oh);
}
/////////////////////////////////////////////////// K A H L U A /////////////////////////////////////////////////////////
void kahluacount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, kahlua1st); 
  shiftOut(data, clock, MSBFIRST, kahlua2nd);
  shiftOut(data, clock, MSBFIRST, kahlua3rd);
  digitalWrite(latch, 1);  
  Serial.print("Kahlua has now pumped ");
  Serial.print(kahlua);
  Serial.print(" quarter ounces, or around ");
  Serial.print(kahlua / 4);
  Serial.println(" full ounces.");   
}
void kahlua5()
{
  kahlua = kahlua + 2;
  kahluacount();
  delay(h);
}
void kahlua75()
{
  kahlua = kahlua + 3;
  kahluacount();  
  delay(tq);
}
void kahlua1()
{
  kahlua = kahlua + 4;
  kahluacount();  
  delay(o);
}
void kahlua15()
{
  kahlua = kahlua + 6;
  kahluacount(); 
  delay(oh);
}
/////////////////////////////////////////////////// M I D O R I /////////////////////////////////////////////////////////
void midoricount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, midori1st); 
  shiftOut(data, clock, MSBFIRST, midori2nd);
  shiftOut(data, clock, MSBFIRST, midori3rd);
  digitalWrite(latch, 1);  
  Serial.print("Midori has now pumped ");
  Serial.print(midori);
  Serial.print(" quarter ounces, or around ");
  Serial.print(midori / 4);
  Serial.println(" full ounces.");   
}
void midori5()
{
  midori = midori + 2;
  midoricount();
  delay(h);
}
void midori1()
{
  midori = midori + 4;
  midoricount(); 
  delay(o);
}
void midori15()
{
  midori = midori + 6;
  midoricount(); 
  delay(oh);
}
void midori2()
{
  midori = midori + 8;
  midoricount(); 
  delay(t);
}
/////////////////////////////////////////////////// T R I P L E  S E C /////////////////////////////////////////////////////////
void tripcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, tripsec1st); 
  shiftOut(data, clock, MSBFIRST, tripsec2nd);
  shiftOut(data, clock, MSBFIRST, tripsec3rd);
  digitalWrite(latch, 1);  
  Serial.print("Triple Sec has now pumped ");
  Serial.print(tripsec);
  Serial.print(" quarter ounces, or around ");
  Serial.print(tripsec / 4);
  Serial.println(" full ounces.");    
}
void trip5()
{
  tripsec = tripsec + 2;
  tripcount();
  delay(h);
}
void trip1()
{
  tripsec = tripsec + 4;
  tripcount();  
  delay(o);
}
void trip15()
{
  tripsec = tripsec + 6;
  tripcount();  
  delay(oh);
}
/////////////////////////////////////////////////// D R Y  V E R M O U T H /////////////////////////////////////////////////////////
void dryvcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, vermouth1st); 
  shiftOut(data, clock, MSBFIRST, vermouth2nd);
  shiftOut(data, clock, MSBFIRST, vermouth3rd);
  digitalWrite(latch, 1);  
  Serial.print("Dry Vermouth has now pumped ");
  Serial.print(vermouth);
  Serial.print(" quarter ounces, or around ");
  Serial.print(vermouth / 4);
  Serial.println(" full ounces.");   
}
void dryvdash()
{
  vermouth = vermouth + 1;
  dryvcount();
  delay(d);
}
void dryv25()
{
  vermouth = vermouth + 1;
  dryvcount(); 
  delay(q);
}
void dryv33()
{
  vermouth = vermouth + 2;
  dryvcount();  
  delay(th);
}
void dryv5()
{
  vermouth = vermouth + 2;
  dryvcount();  
  delay(h);
}
void dryv75()
{
  vermouth = vermouth + 3;
  dryvcount();  
  delay(tq);
}
void dryv1()
{
  vermouth = vermouth + 4;
  dryvcount();  
  delay(o);
}
void dryv15()
{
  vermouth = vermouth + 6;
  dryvcount(); 
  delay(oh);
}
void dryv2()
{
  vermouth = vermouth + 8;
  dryvcount();  
  delay(t);
}
/////////////////////////////////////////////////// S O U R  M I X /////////////////////////////////////////////////////////
void sourcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, sour1st); 
  shiftOut(data, clock, MSBFIRST, sour2nd);
  shiftOut(data, clock, MSBFIRST, sour3rd);
  digitalWrite(latch, 1);  
  Serial.print("Sour mix has now pumped ");
  Serial.print(sour);
  Serial.print(" quarter ounces, or around ");
  Serial.print(sour / 4);
  Serial.println(" full ounces.");  
}
void sour5()
{
  sour = sour + 2;
  sourcount();
  delay(h);
}
void sour1()
{
  sour = sour + 4;
  sourcount(); 
  delay(o);
}
void sour15()
{
  sour = sour + 6;
  sourcount();  
  delay(oh);
}
/////////////////////////////////////////////////// G R E N A D I N E /////////////////////////////////////////////////////////
void grenadcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, grenad1st); 
  shiftOut(data, clock, MSBFIRST, grenad2nd);
  shiftOut(data, clock, MSBFIRST, grenad3rd);
  digitalWrite(latch, 1);  
  Serial.print("Grenadine has now pumped ");
  Serial.print(grenad);
  Serial.print(" quarter ounces, or around ");
  Serial.print(grenad / 4);
  Serial.println(" full ounces.");  
}
void grenaddash()
{
  grenad = grenad + 1;
  grenadcount();
  delay(d);
}
void grenad25()
{
  grenad = grenad + 1;
  grenadcount();
  delay(q);
}
void grenad5()
{
  grenad = grenad + 2;
  grenadcount(); 
  delay(h);
}
void grenad1()
{
  grenad = grenad + 4;
  grenadcount();  
  delay(o);
}
void grenad15()
{
  grenad = grenad + 6;
  grenadcount();  
  delay(oh);
}
/////////////////////////////////////////////////// S I M P L E  S Y R U P /////////////////////////////////////////////////////////
void syrupcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, syrup1st); 
  shiftOut(data, clock, MSBFIRST, syrup2nd);
  shiftOut(data, clock, MSBFIRST, syrup3rd);
  digitalWrite(latch, 1); 
  Serial.print("Simple Syrup has now pumped ");
  Serial.print(syrup);
  Serial.print(" quarter ounces, or around ");
  Serial.print(syrup / 4);
  Serial.println(" full ounces.");  
}
void syrup5()
{
  syrup = syrup + 2;
  syrupcount();
  delay(h);
}
void syrup1()
{
  syrup = syrup + 4;
  syrupcount();  
  delay(o);
}
void syrup15()
{
  syrup = syrup + 6;
  syrupcount();  
  delay(oh);
}
/////////////////////////////////////////////////// C R A N B E R R Y  J U I C E /////////////////////////////////////////////////////////
void crancount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, cran1st); 
  shiftOut(data, clock, MSBFIRST, cran2nd);
  shiftOut(data, clock, MSBFIRST, cran3rd);
  digitalWrite(latch, 1); 
  Serial.print("Cranberry Juice has now pumped ");
  Serial.print(cran);
  Serial.print(" quarter ounces, or around ");
  Serial.print(cran / 4);
  Serial.println(" full ounces."); 
}
void cran5()
{
  cran = cran + 2;
  crancount(); 
  delay(h);
}
void cran1()
{
  cran = cran + 4;
  crancount();  
  delay(o);
}
void cran15()
{
  cran = cran + 6;
  crancount();  
  delay(oh);
}
/////////////////////////////////////////////////// O R A N G E  J U I C E /////////////////////////////////////////////////////////
void ojcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, orange1st); 
  shiftOut(data, clock, MSBFIRST, orange2nd);
  shiftOut(data, clock, MSBFIRST, orange3rd);
  digitalWrite(latch, 1); 
  Serial.print("Orange Juice has now pumped ");
  Serial.print(orange);
  Serial.print(" quarter ounces, or around ");
  Serial.print(orange / 4);
  Serial.println(" full ounces.");  
}
void oj5()
{
  orange = orange + 2;
  ojcount();
  delay(h);
}
void oj1()
{
  orange = orange + 4;
  ojcount();  
  delay(o);
}
void oj15()
{
  orange = orange + 6;
  ojcount();  
  delay(oh);
}
/////////////////////////////////////////////////// P I N E A P P L E  J U I C E /////////////////////////////////////////////////////////
void pjcount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, pine1st); 
  shiftOut(data, clock, MSBFIRST, pine2nd);
  shiftOut(data, clock, MSBFIRST, pine3rd);
  digitalWrite(latch, 1);  
  Serial.print("Pineapple Juice has now pumped ");
  Serial.print(pine);
  Serial.print(" quarter ounces, or around ");
  Serial.print(pine / 4);
  Serial.println(" full ounces."); 
}
void pj5()
{
  pine = pine + 2;
  pjcount();
  delay(h);
}
void pj1()
{
  pine = pine + 4;
  pjcount();  
  delay(o);
}
void pj15()
{
  pine = pine + 6;
  pjcount();  
  delay(oh);
}

/////////////////////////////////////////////////// C O L A /////////////////////////////////////////////////////////
void colacount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, cola1st); 
  shiftOut(data, clock, MSBFIRST, cola2nd);
  shiftOut(data, clock, MSBFIRST, cola3rd);
  digitalWrite(latch, 1); 
  Serial.print("Cola has now pumped ");
  Serial.print(cola);
  Serial.print(" quarter ounces, or around ");
  Serial.print(cola / 4);
  Serial.println(" full ounces."); 
}
void cola5()
{
  cola = cola + 2;
  colacount();
  delay(h);
}
void cola1()
{
  cola = cola + 4;
  colacount(); 
  delay(o);
}
void cola15()
{
  cola = cola + 6;
  colacount();  
  delay(oh);
}
/////////////////////////////////////////////////// S P R I T E /////////////////////////////////////////////////////////
void spritecount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, sprite1st); 
  shiftOut(data, clock, MSBFIRST, sprite2nd);
  shiftOut(data, clock, MSBFIRST, sprite3rd);
  digitalWrite(latch, 1);  
  Serial.print("Sprite has now pumped ");
  Serial.print(sprite);
  Serial.print(" quarter ounces, or around ");
  Serial.print(sprite / 4);
  Serial.println(" full ounces.");   
}
void sprite5()
{
  sprite = sprite + 2;
  spritecount();
  delay(h);
}
void sprite1()
{
  sprite = sprite + 4;
  spritecount(); 
  delay(o);
}
void sprite15()
{
  sprite = sprite + 6;
  spritecount();  
  delay(oh);
}
/////////////////////////////////////////////////// T O N I C /////////////////////////////////////////////////////////
void toniccount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, tonic1st); 
  shiftOut(data, clock, MSBFIRST, tonic2nd);
  shiftOut(data, clock, MSBFIRST, tonic3rd);
  digitalWrite(latch, 1);  
  Serial.print("Tonic has now pumped ");
  Serial.print(tonic);
  Serial.print(" quarter ounces, or around ");
  Serial.print(tonic / 4);
  Serial.println(" full ounces.");  
}
void tonic5()
{
  tonic = tonic + 2;
  toniccount();
  delay(h);
}
void tonic1()
{
  tonic = tonic + 4;
  toniccount();  
  delay(o);
}
void tonic15()
{
  tonic = tonic + 6;
  toniccount();  
  delay(oh);
}
/////////////////////////////////////////////////// G I N G E R  A L E /////////////////////////////////////////////////////////
void gingercount()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, ginger1st); 
  shiftOut(data, clock, MSBFIRST, ginger2nd);
  shiftOut(data, clock, MSBFIRST, ginger3rd);
  digitalWrite(latch, 1); 
  Serial.print("Ginger Ale has now pumped ");
  Serial.print(ginger);
  Serial.print(" quarter ounces, or around ");
  Serial.print(ginger / 4);
  Serial.println(" full ounces.");   
}
void ginger5()
{
  ginger = ginger + 2;
  gingercount();
  delay(h);
}
void ginger1()
{
  ginger = ginger + 4;
  gingercount(); 
  delay(o);
}
void ginger15()
{
  ginger = ginger + 6;
  gingercount(); 
  delay(oh);
}
/////////////////////////////////////////////////// W A T E R /////////////////////////////////////////////////////////
void water1()
{
  digitalWrite(latch, 0);
  shiftOut(data, clock,MSBFIRST, water1st); 
  shiftOut(data, clock, MSBFIRST, water2nd);
  shiftOut(data, clock, MSBFIRST, water3rd);
  digitalWrite(latch, 1);
  water = water + 4;
  Serial.print("Water has now pumped ");
  Serial.print(water);
  Serial.print(" quarter ounces, or around ");
  Serial.print(water / 4);
  Serial.println(" full ounces.");  
  delay(o);
}

/////////////////////////////////////////////////// Warning Light Blink /////////////////////////////////////////////////////////

void flash()
{
      digitalWrite(LED, 1);
   delay (250);
      digitalWrite(LED, 0);
   delay (250);
}

Like I said... it's long. Still only about 18,000 bytes compiled though... 25,000 if I un-comment some more "if" statements.

Try using the flash library to remove the strings from RAM. That will free up quite a bit of space for you.

I don’t know anything about the flash library… I’ll root around and find somewhere I can read up on it!

ALSO, I have attached my sketch here now, in case that is more manageable.

barbotV8.ino (47.8 KB)

Use the F macro to wrap your constant strings e.g.

      Udp.write(F("Brantini- Serve with a lemon twist. Enjoy!"));    // Send Message back to iPhone

That should free up RAM in abundance.

You could have a lot less code by making flash() take an argument - the number of times to flash. Move the for loops into the flash() function.

The next time that the forum software tells you about the character count limit, attach your code. Reading code spread over half a dozen posts is difficult.

Ok - I only looked at the first segment of code, but one thing that stood out to me is the sheer repetitiveness of it; any time your code looks like that, it is a sure sign you need a function (and probably a simple array or two). I'm willing to bet your code could be reduced greatly if you did that.

Use the F macro to wrap your constant strings

Awesome- I will!

Move the for loops into the flash() function.

I would, but each “for” loop is different. The number of times to flash changes every time (this corresponds to which bottle is running low- so if bottle number 11 is getting low, then that “for” loop knows to flash the light eleven times)

if (rumlt >= 180) {
for (int x = 0; x < 11; x++){

and here is the one for bottle #2:

if (rumlt >= 180) {
for (int x = 0; x < 2; x++){

So I wouldn’t know how to move that into the flash() function because it is different each time…

attach your code.

Yeah, sorry about that. I didn’t know I could until afterwards. I have attached it in an earlier reply in this thread, and I have attached it again here.

one thing that stood out to me is the sheer repetitiveness of it; any time your code looks like that, it is a sure sign you need a function and maybe an array or two

Two things:

  1. The code definitely looks repetitive. I don’t know how much less repetitive I can make it though. The reason for this is I have 23 different little pumps, pumping 23 different liquids. Thus, I need 23 distinctions in code for everything that I do (don’t I?). THEN- I take these pumps, and I make them work together in about 100 different drink “recipes”. These “recipes” use the functions you’ll see near the end of the code for different liquids and different lengths of time to run the pumps (this corresponds to measurements, like one once, 1.5 ounces, etc.). These liquid measurement functions have names like vodka1(); for one ounce of vodka, whiskey5(); for a half ounce of whiskey, or gin15(); for an ounce and a half of gin. I am not sure how much less repetitive I can make something like this?

  2. I am so new to this electronics game (actually started 100% fresh at the beginning of this month) that while I have seen arrays in passing on tutorial sites and in a couple examples… I don’t know what they actually do, how to use them, or how they could help me out here. I’ll look into them!

barbotV8.ino (47.8 KB)