Statement question

I am tryiing to build a menu system to allow paramter changes for a "water drop" controller
The final product will ask me:

  • for the number of drops ( 1, 2, or 3 drops)
  • how long to open the valve in millisecs (control drop size)
  • how much drop separation between drops (in millisecs) if there are multiple drops

The controller will then open and close a valve to generate the drop stream.

I am having trouble with the following code. I do not understand what
this statement does. int get_key(unsigned int input) and why it
does not seem to need the ; at the end of it.

The first example code compiles and runs on my Arduino Uno and the DFRobot LCD Kepad Shield.

When I try and incorporate this code as a subroutine I get a compiler error.

Here is the error message:

NEW_MENU_REV3.cpp: In function 'void drpcount()':
NEW_MENU_REV3:188: error: a function-definition is not allowed here before '{' token
OutLoop_Rev1:68: error: expected `}' at end of input

The curly brace following this statement: int get_key(unsigned int input) is highlighted

Here is the code that compiles without error:

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char msgs[5][15] = {
  "Right Key OK ",   // Value = 0
  "Up Key OK    ",   // Value = 1
  "Down Key OK  ",   // Value = 2
  "Left Key OK  ",   // Value = 3
  "Select Key OK" }; // Value = 4

int  adc_key_val[5] ={
  30, 150, 360, 535, 760 };

int NUM_KEYS = 5;
int adc_key_in;
int key=-1;
int oldkey=-1;
int loopcount = 0;
int DropCount = 2;
int pulseWidth0 = 1000;  //Valve ON Time  (Drop Size)
int pulseWidth1 = 1000;  //Valve ON Time  (Drop Size)
int pulseWidth2 = 1000;  //Valve ON Time  (Drop Size)
int pulseSep0 = 300;    // Drop Seperation time  (Time Between Drops)
int pulseSep1 = 350;    // Drop Seperation time  (Time Between Drops)
int pulseSep2 = 400;    // Drop Seperation time  (Time Between Drops)
int sensorValue =0;
int mapvalue = 0;
int reading = 0;
int backLight = 10;
int selectPin = 6;
int valveControl =11;    // Output pin to turn valve ON & OFF
int ledpin = 13;
int ReadCount = 0;


void setup() 
{ 
  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat
  pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
  lcd.begin(16,2);
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  digitalWrite(13, LOW);    // Turn OFF board LED
  digitalWrite(backLight,HIGH); // Turn ON LCD Backlight
  lcd.clear();
 
    lcd.print("Drop Count");
    lcd.setCursor(13,0);
    lcd.print(DropCount);
    lcd.setCursor(13,0);
    //lcd.cursor();   //Turn on the cursor
}

void loop() 
{
  adc_key_in = analogRead(0);    // read the value from the sensor  
  //digitalWrite(13, HIGH);  
  key = get_key(adc_key_in);    // convert into key press
  if (key != oldkey) // if keypress is detected
  {
    delay(50);      // wait for debounce time
    adc_key_in = analogRead(0);    // read the value from the sensor  
    key = get_key(adc_key_in);    // convert into key press
    if (key != oldkey)             
    {           
      oldkey = key;
      if (key >=0)
      {  
          lcd.setCursor(13, 0);  //line=1, pos 13
          lcd.setCursor(0,1);
          lcd.print("             ");        
          lcd.setCursor(0,0);
          lcd.print("Drop Count");
          lcd.setCursor(13,0);
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
          if (key == 1)
          {
          DropCount = DropCount++;
          if (DropCount == 4)

          { 
            DropCount = 3;
            lcd.setCursor(0,1);
            lcd.print("Max Drops = 3");
            lcd.setCursor(13,0);
          }

          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }

        else if (key == 2)
        {
          lcd.setCursor(13, 0);  //line=1, pos 13
          DropCount = DropCount--;
          lcd.print(DropCount);
          lcd.setCursor(13,0);
          if (DropCount == 0)
          { 
            DropCount = 1;
            lcd.setCursor(0,1);
            lcd.print("Min Drops = 1");
            lcd.setCursor(13,0);
          }
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
       }
      }
        else if (key == 4)
    
       {
//         outloop();
         delay(1000);
         lcd.setCursor(13,0);
         lcd.print(DropCount);
         lcd.setCursor(0,1);
       }    
       }

// Convert ADC value to key number

int get_key(unsigned int input)
     {   
  int k;
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {  
      return k;  
    }
  }
  if (k >= NUM_KEYS)
    k = -1;     // No valid key pressed
  return k;
}

The code incorporating the first sketch as a subroutine will be posted in a second message because of
message size limitations:

I am at a loss as to why it compiles in the first example but generates errors in the second.

Did I miss a declaration or am I missing one of these ; somewhere?

Here is the code that does NOT compile:

[code] 

#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key = 0;
int Main_key_in = 0;
int adc_key_in = 0;
int key = -1;
int oldkey = 0;
int k =0;
int NUM_KEYS = 5;
int adc_key_val = 0;
//int get_key = 0;
int get_key(unsigned int input);
int loopcount = 0;
int DropCount = 2;
int pulseWidth0 = 1000;
int pulseWidth1 = 1000;
int pulseWidth2 = 10;
int pulseSep0 = 300;
int pulseSep1 = 350;
int pulseSep2 = 40;
int sensorValue =0;
int mapvalue = 0;
int reading = 0;
int backLight = 10;
int selectPin = 6;
int valveControl =7;
int ledpin = 13;
int ReadCount = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
  
// read the buttons
int read_LCD_buttons()
{
 Main_key_in = analogRead(0);      // read the value from the sensor 
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (Main_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (Main_key_in < 50)   return btnRIGHT;  
 if (Main_key_in < 195)  return btnUP; 
 if (Main_key_in < 380)  return btnDOWN; 
 if (Main_key_in < 555)  return btnLEFT; 
 if (Main_key_in < 790)  return btnSELECT;   
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{
  lcd.begin(16, 2);              // start the library
  pinMode(backLight, OUTPUT);
  pinMode(ledpin,OUTPUT);
  pinMode(valveControl,OUTPUT);
  pinMode(selectPin, INPUT);
  lcd.setCursor(0,0);
  digitalWrite(backLight,HIGH);   //Backlight ON
  lcd.print("1 Drop Count"); // print a simple message
  lcd.setCursor(0,1);
  lcd.print("2  Repeat ");
}
  
void loop()
{
 lcd.setCursor(10,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(millis()/1000);      // display seconds elapsed since power-up

 
 lcd.setCursor(0,1);  // move to the begining of the second line
 lcd.print("2  Repeat ");
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print(" RIGHT");
     break;
     }
     
   case btnLEFT:
     {
     lcd.print("  LEFT");
     break;
     }
     
   case btnUP:
     {
      lcd.print ("    UP");
      drpcount();
     break;
     }
     
   case btnDOWN:
     {
     lcd.print("  DOWN");
     break;
     }
     
   case btnSELECT:
     {
   //  lcd.print("SELECT");
     outloop ();
     break;
     }
     
     case btnNONE:
     {
     //lcd.print("  NONE");
    // lcd.print(DropCount);
     break;
     }
 }
 
}
void drpcount() 
{
  adc_key_in = analogRead(0);    // read the value from the sensor  
  //digitalWrite(13, HIGH);  
  key = get_key(adc_key_in);    // convert into key press
  if (key != oldkey) // if keypress is detected
  {
    delay(50);      // wait for debounce time
    adc_key_in = analogRead(0);    // read the value from the sensor  
    key = get_key(adc_key_in);    // convert into key press
    if (key != oldkey)             
    {           
      oldkey = key;
      if (key >=0)
      {  
          lcd.setCursor(13, 0);  //line=1, pos 13
          lcd.setCursor(0,1);
          lcd.print("             ");        
          lcd.setCursor(0,0);
          lcd.print("Drop Count");
          lcd.setCursor(13,0);
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
          if (key == 1)
          {
          DropCount = DropCount++;
          if (DropCount == 4)

          { 
            DropCount = 3;
            lcd.setCursor(0,1);
            lcd.print("Max Drops = 3");
            lcd.setCursor(13,0);
          }

          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }

        else if (key == 2)
        {
          lcd.setCursor(13, 0);  //line=1, pos 13
          DropCount = DropCount--;
          lcd.print(DropCount);
          lcd.setCursor(13,0);
          if (DropCount == 0)
          { 
            DropCount = 1;
            lcd.setCursor(0,1);
            lcd.print("Min Drops = 1");
            lcd.setCursor(13,0);
          }
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
       }
           return;
      }
      
       

// Convert ADC value to key number

int get_key(unsigned int input)
     {   
  int k;
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {  
      return k;  
    }
  }
  if (k >= NUM_KEYS)
    k = -1;     // No valid key pressed
  return k;
}

[/code]

Any help in figuring this dilemma out will be greatly appreciated.

RWW

This code is defining a function. You can't define a function inside another function. Just move it outside drpcount() and you should be good.

int get_key(unsigned int input)
{   
...
}

I tried moving that statement to the main declaration area and the compiler
blew up with more errors. This statement is now
the one that is highlighted:

if (input < adc_key_val[k])

Here are the compiler error messaages:

NEW_MENU_REV3.cpp: In function 'void drpcount()':
NEW_MENU_REV3:193: error: invalid types 'int[int]' for array subscript
NEW_MENU_REV3:195: error: return-statement with a value, in function returning 'void'
NEW_MENU_REV3:200: error: return-statement with a value, in function returning 'void'
OutLoop_Rev1:2: error: a function-definition is not allowed here before '{' token
OutLoop_Rev1:68: error: expected `}' at end of input

RWW

adc_key_val isn't an array, so you can't give it a subscript.
(it was an array in your first post)

AWOL

would K be the subscript you are talking about? And
if so can you tell me why the same code runs in the
initial example?

RWW

First code:

int  adc_key_val[5] ={
  30, 150, 360, 535, 760 };

Second code:int adc_key_val = 0;

I think the statement is defining adc_key_in to be an integer in both sketches. Am I correct in that assumption.

In the first sketch the program compiles. In the second sketch it does not. Same exact statement in the
same exact place in the code. I am not a programmer
so please tell me what I need to do to fix this little dilemma.

Maniacbug suggested that I move the statement
outside of drpcount which I did. That caused even more errors that AWOL is telling me are about arrays. No way
was I trying to do ANYTHING with an array. Arrays are way beyond my newb level of understanding of the C++
language.

RWW

AWOL:
No way was I trying to do ANYTHING with an array.

...

First code:

int  adc_key_val[5] ={

30, 150, 360, 535, 760 };

That is an array.

You have declared adc_key_val to be an array of 5 items (that is what [5] means). They have values, that is: 30, 150, 360, 535, 760

In other words, 5 integers.

OK, then I still don't understand why it works in one sketch and not the other.

The code is the same in both sketches. There is just extra code in the one that does not compile. :~ :~ :~

RWW

RogerW:
The code is the same in both sketches. There is just extra code in the one that does not compile.

The code is the same, but different, huh?

In the one that doesn't compile you have near the top:

int adc_key_val = 0;

That is defining a single int (not an array).

Then further down you get an error on:

 if (input < adc_key_val[k])

That is trying to index into an array (with the index "k").

The code that worked had this near the top:

int  adc_key_val[5] ={
  30, 150, 360, 535, 760 };

So it isn't the same. You have changed an array into a not-array. You can't change:

int adc_key_val = 0;

to:

int  adc_key_val[5] ={
  30, 150, 360, 535, 760 };

and then say "the code is the same". It isn't.

I think the statement is defining adc_key_in to be an integer in both sketches. Am I correct in that assumption.

No you are not. One is an integer, the other is an array of integers. It's the difference between a cookie and a jar of cookies. You don't eat a jar, you eat the individual cookie. And you don't say "get a cookie from inside a cookie", because a cookie isn't a container.

I think the statement is defining adc_key_in

We're not talking about "adc_key_in", we're talking about "adc_key_val".
Newb or not, you must be able to see that they are not the same thing.

Oops. I didn't look all that closely at what variable he is talking about. The error, after all, was on the line:

    if (input < adc_key_val[k])

And that is the variable that changed from an array to an int.

OK, I think I have the Array declarations fixed.

Now I am getting this error when I compile:

sketch_apr07a.cpp: In function 'void drpcount()':
sketch_apr07a:197: error: return-statement with a value, in function returning 'void'
sketch_apr07a:202: error: return-statement with a value, in function returning 'void'
sketch_apr07a:203: error: expected `}' at end of input

This is the statement that is higlighted:

return k;

It is in the

for loop

that is supposed to return which key is pressed.

RWW

#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key = 0;
int Main_key_in = 0;
int adc_key_in = 0;
int key = -1;
int oldkey = -1;
int k =0;
int NUM_KEYS = 5;


int get_key(unsigned int input);
int input = 0;
int  adc_key_val[5] ={
  30, 150, 360, 535, 760 };


int DropCount = 2;
int pulseWidth0 = 1000;
int pulseWidth1 = 1000;
int pulseWidth2 = 10;
int pulseSep0 = 300;
int pulseSep1 = 350;
int pulseSep2 = 40;


int backLight = 10;

int valveControl =11;
int ledpin = 13;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
  
// read the buttons
int read_LCD_buttons()
{
 Main_key_in = analogRead(0);      // read the value from the sensor 
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (Main_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (Main_key_in < 50)   return btnRIGHT;  
 if (Main_key_in < 195)  return btnUP; 
 if (Main_key_in < 380)  return btnDOWN; 
 if (Main_key_in < 555)  return btnLEFT; 
 if (Main_key_in < 790)  return btnSELECT;   
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{
  lcd.begin(16, 2);              // start the library
  pinMode(backLight, OUTPUT);
  pinMode(ledpin,OUTPUT);
  pinMode(valveControl,OUTPUT);

  lcd.setCursor(0,0);
  digitalWrite(backLight,HIGH);   //Backlight ON
  lcd.print("1 Drop Count"); // print a simple message
  lcd.setCursor(0,1);
  lcd.print("2  Repeat ");
}
  
void loop()
{
// lcd.setCursor(10,1);            // move cursor to second line "1" and 9 spaces over
// lcd.print(millis()/1000);      // display seconds elapsed since power-up

 
 lcd.setCursor(0,1);  // move to the begining of the second line
 lcd.print("2  Repeat ");
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print(" RIGHT");
     break;
     }
     
   case btnLEFT:
     {
     lcd.print("  LEFT");
     break;
     }
     
   case btnUP:
     {
      lcd.print ("    UP");
      drpcount();
     break;
     }
     
   case btnDOWN:
     {
     lcd.print("  DOWN");
     break;
     }
     
   case btnSELECT:
     {
     lcd.print("SELECT");
   //  outloop ();
     break;
     }
     
     case btnNONE:
     {
     //lcd.print("  NONE");
    // lcd.print(DropCount);
     break;
     }
 }
 
}
void drpcount() 
{
  adc_key_in = analogRead(0);    // read the value from the sensor  
  //digitalWrite(13, HIGH);  
  key = get_key(adc_key_in);    // convert into key press
  if (key != oldkey) // if keypress is detected
  {
    delay(50);      // wait for debounce time
    adc_key_in = analogRead(0);    // read the value from the sensor  
    key = get_key(adc_key_in);    // convert into key press
    if (key != oldkey)             
    {           
      oldkey = key;
      if (key >=0)
      {  
          lcd.setCursor(13, 0);  //line=1, pos 13
          lcd.setCursor(0,1);
          lcd.print("             ");        
          lcd.setCursor(0,0);
          lcd.print("Drop Count");
          lcd.setCursor(13,0);
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
          if (key == 1)
          {
          DropCount = DropCount++;
          if (DropCount == 4)

          { 
            DropCount = 3;
            lcd.setCursor(0,1);
            lcd.print("Max Drops = 3");
            lcd.setCursor(13,0);
          }

          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }

        else if (key == 2)
        {
          lcd.setCursor(13, 0);  //line=1, pos 13
          DropCount = DropCount--;
          lcd.print(DropCount);
          lcd.setCursor(13,0);
          if (DropCount == 0)
          { 
            DropCount = 1;
            lcd.setCursor(0,1);
            lcd.print("Min Drops = 1");
            lcd.setCursor(13,0);
          }
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
       }
           return;
      }
      
       

// Convert ADC value to key number

//int get_key(unsigned int input)
     {   
  int k;
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {  
      return k;  
    }
  }
  if (k >= NUM_KEYS)
    k = -1;     // No valid key pressed
  return k;
}

You can't return a value from a function declared "void" - change the return type of "drpcount" to "int".

I changed the void drpcount() statement to int drpcount()

and got this error:

New_Menu_Rev4.cpp: In function 'int drpcount()':
New_Menu_Rev4:183: error: return-statement with no value, in function returning 'int'

with the Return; statement highlighted.

So I changed the Return statement to Return(DropCount); and it compiled.

Did not work the way I want it to but at least it compiles. Now to fix m program logic so it does what I want.

Thanks very much to all who contributed to this thread.

RWW

Some compiler messages can be a bit cryptic, but this one

return-statement with no value, in function returning 'int'

couldn't be clearer.

You can't return a value from a function declared "void" - change the return type of "drpcount" to "int".

He had "int get_key" declared for the function, but that entire line commented out. :stuck_out_tongue:

// Convert ADC value to key number

//int get_key(unsigned int input)
     {

I suspect this was to get rid of an error message about mismatched braces, but honestly, you can't just change the logic like that in the hope of getting it to compile. Sure, getting rid of error messages is important, but you have to look at why there are there. Randomly adding "{" symbols, or commenting out function declarations, is not the way to go. You only shift the problem from compile problems to runtime problems. As you say:

Did not work the way I want it to but at least it compiles.

At least the compile errors give you a hint as to where you may have mis-pasted code from other sources.

The code below compiles. I put the function header back and added back in a missing brace ("}"). I certainly don't claim that it runs correctly.

#include <LiquidCrystal.h>
#include <Wire.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key = 0;
int Main_key_in = 0;
int adc_key_in = 0;
int key = -1;
int oldkey = -1;
int k =0;
int NUM_KEYS = 5;


int get_key(unsigned int input);
int input = 0;
int  adc_key_val[5] ={
  30, 150, 360, 535, 760 };


int DropCount = 2;
int pulseWidth0 = 1000;
int pulseWidth1 = 1000;
int pulseWidth2 = 10;
int pulseSep0 = 300;
int pulseSep1 = 350;
int pulseSep2 = 40;


int backLight = 10;

int valveControl =11;
int ledpin = 13;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
 
  
// read the buttons
int read_LCD_buttons()
{
 Main_key_in = analogRead(0);      // read the value from the sensor 
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (Main_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (Main_key_in < 50)   return btnRIGHT;  
 if (Main_key_in < 195)  return btnUP; 
 if (Main_key_in < 380)  return btnDOWN; 
 if (Main_key_in < 555)  return btnLEFT; 
 if (Main_key_in < 790)  return btnSELECT;   
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{
  lcd.begin(16, 2);              // start the library
  pinMode(backLight, OUTPUT);
  pinMode(ledpin,OUTPUT);
  pinMode(valveControl,OUTPUT);

  lcd.setCursor(0,0);
  digitalWrite(backLight,HIGH);   //Backlight ON
  lcd.print("1 Drop Count"); // print a simple message
  lcd.setCursor(0,1);
  lcd.print("2  Repeat ");
}
  
void loop()
{
// lcd.setCursor(10,1);            // move cursor to second line "1" and 9 spaces over
// lcd.print(millis()/1000);      // display seconds elapsed since power-up

 
 lcd.setCursor(0,1);  // move to the begining of the second line
 lcd.print("2  Repeat ");
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print(" RIGHT");
     break;
     }
     
   case btnLEFT:
     {
     lcd.print("  LEFT");
     break;
     }
     
   case btnUP:
     {
      lcd.print ("    UP");
      drpcount();
     break;
     }
     
   case btnDOWN:
     {
     lcd.print("  DOWN");
     break;
     }
     
   case btnSELECT:
     {
     lcd.print("SELECT");
   //  outloop ();
     break;
     }
     
     case btnNONE:
     {
     //lcd.print("  NONE");
    // lcd.print(DropCount);
     break;
     }
 }
 
}
void drpcount() 
{
  adc_key_in = analogRead(0);    // read the value from the sensor  
  //digitalWrite(13, HIGH);  
  key = get_key(adc_key_in);    // convert into key press
  if (key != oldkey) // if keypress is detected
  {
    delay(50);      // wait for debounce time
    adc_key_in = analogRead(0);    // read the value from the sensor  
    key = get_key(adc_key_in);    // convert into key press
    if (key != oldkey)             
    {           
      oldkey = key;
      if (key >=0)
      {  
          lcd.setCursor(13, 0);  //line=1, pos 13
          lcd.setCursor(0,1);
          lcd.print("             ");        
          lcd.setCursor(0,0);
          lcd.print("Drop Count");
          lcd.setCursor(13,0);
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
          if (key == 1)
          {
          DropCount = DropCount++;
          if (DropCount == 4)

          { 
            DropCount = 3;
            lcd.setCursor(0,1);
            lcd.print("Max Drops = 3");
            lcd.setCursor(13,0);
          }

          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }

        else if (key == 2)
        {
          lcd.setCursor(13, 0);  //line=1, pos 13
          DropCount = DropCount--;
          lcd.print(DropCount);
          lcd.setCursor(13,0);
          if (DropCount == 0)
          { 
            DropCount = 1;
            lcd.setCursor(0,1);
            lcd.print("Min Drops = 1");
            lcd.setCursor(13,0);
          }
          lcd.print(DropCount);
          lcd.setCursor(13,0);
        }
       }
           return;
      }
      
}       

// Convert ADC value to key number

int get_key(unsigned int input)
     {   
  int k;
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {  
      return k;  
    }
  }
  if (k >= NUM_KEYS)
    k = -1;     // No valid key pressed
  return k;
}

The reason it does not run right is a logic problem in the code. I will figure that out
and then continue to build.

Again, A HUGE thanks to ALL who chipped in with suggestions on what I needed
to do to get past the error messages.

RWW