Switch - Not defined in this scope

I changed the sample routine of my keypad shield for getting the current button. Instead of separate if clauses I now use if else, … However, now it throws a not defined error for all constants declared by #define. If I change this definitions to constants, same happens. What’s the trick?

int lcd_key     = 0;
int adc_key_in  = 0;
int lastButton  = 0;
int curButton   = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons()
{
  adc_key_in = analogRead(0);  // read the value from the sensor
  
  if (adc_key_in < 50)
    curButton = btnRIGHT;
  else if (adc_key_in < 195)
    curButton = btnUP;
  else if (adc_key_in < 380)
    curButton = btnDOWN;
  else if (adc_key_in < 555)
    curButton = btnLEFT;
  else if (adc_key_in < 790)
    curButton = btnSELECT;
  else 
  curButton = btnNone;

  if (curButton == lastButton)
    return btnNone;
  else return curButton;  // when all others fail, return this...
}

You define ‘btnNONE’, then try to use ‘btnNone’.

And it’s not for all defines like you said, just for that one.

lastButton never changes

:) You helped me out a lot. I was so blind. Such a trivial thing. Already spend one hour and could not find it. Thanks!

Assignment of last button is inserted now, the function was not finished.

Now you know. When you get an error like that, look very carefully at the named variables and check the spelling.

Spelling, AND capitalization.

For C-based languages I include capitalization with spelling. ASCII 65 is not equal to ASCII 97.