Arduino Mega Compilation errors

HI
I'm new to the forum and Arduino software and I've been working on some code cycling up and down 4 relays and toggling an Led on and off from a 4 x 1 keypad with reference to Gnd as I'm using internal pullups and the Arduino Mega.
It worked ok until i added code for the left and right keys and now i cant get it to compile and i cant seem to clear the errors and wondered if anyone could take a look at all and try to get it to compile. Thanks

//4 Aspect CLS controller
//RD
//V1.1
//keys
//left = aspect Down
//Down = aspect off
//UP = Aspect ON
//Right = aspect UP


#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int inPinRight = A12;
const int inPinLft = A11
const int inPinUp = A13;
const int inPinDown = A14;
int Aspect = 0;
int buttonUpState = 0;
int buttonDownState = 0;
int buttonRightState = 0;
int buttonLeftState = 0 
int prevBtnUp = LOW;
int prevBtnDwn = LOW;
int prevBtnRgt = LOW;
int prevBtnLft = LOW;
unsigned long lastBtnUp = 0;
unsigned long lastBtnDwn = 0;
unsigned long lastBtnRgt = 0,
unsigned long lastBtnLft = 0;
int DebounceTime = 100;

int Out1 = 24;
int Out2 = 25;
int Out3 = 26;
int Out4 = 27;
int Out5 = A0;



void setup() 
{
  pinMode(inPinUp, INPUT_PULLUP);
  pinMode(inPinDown, INPUT_PULLUP);
  pinMode(inPinRight, INPUT_PULLUP);
  pinMode(inPinleft, INPUT_PULLUP);
  pinMode(Out1, OUTPUT);
  pinMode(Out2, OUTPUT);
  pinMode(Out3, OUTPUT);
  pinMode(Out4, OUTPUT);
  pinMode(Out5, OUTPUT);

  digitalWrite(Out1, HIGH);  //initial state
  digitalWrite(Out2, HIGH);
  digitalWrite(Out3, HIGH);
  digitalWrite(Out4, HIGH);
  digitalWrite(Out5, HIGH);

  lcd.begin(16, 2);
  lcd.print("CLS  R-Y-G-YY");
}

void AspectFunction() {
  switch (Aspect) {
    case 1:
      lcd.setCursor(2, 1);
      lcd.print("RED      ");
      digitalWrite(Out1, LOW);
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      break;

    case 2:
      lcd.setCursor(0, 1);
      lcd.print("YELL     ");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, LOW);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      break;

    case 3:
      lcd.setCursor(0, 1);
      lcd.print("GREEN      ");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, LOW);
      digitalWrite(Out4, HIGH);
      break;

    case 4:
      lcd.setCursor(0, 1);
      lcd.print("YELL-YELL");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, LOW);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, LOW);
      break;
  }
}

void loop() {

  buttonUpState = digitalRead(inPinUp);
  buttonDownState = digitalRead(inPinDown);
  buttonRightState = digitalRead(inPinRight);
  buttonLeftState = digitalRead(inPinLeft);

     //Up Button

    if (buttonUpState == HIGH && prevBtnUp == LOW)
   {
     if (millis() - lastBtnUp > DebounceTime) 
     {
      digitalWrite(Out1, HIGH);  //new
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      delay(500);  // new
      Aspect++;

      if (Aspect > 3)
     {
        Aspect = 4;
     }
      lastBtnUp = millis();
      AspectFunction();
    }
  }
  prevBtnUp = buttonUpState;


  //Down Button

  if (buttonDownState == HIGH && prevBtnDwn == LOW) {
    if (millis() - lastBtnDwn > DebounceTime) {
      digitalWrite(Out1, HIGH);  //new
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      delay(500);  // new
      Aspect--;
      if (Aspect < 1) {
        Aspect = 1;
      }
      lastBtnDwn = millis();
      AspectFunction();
    }
  }
  prevBtnDwn = buttonDownState;


  // Right Button

  if (buttonRightState == HIGH && prevBtnRgt == LOW) {
    if (millis() - lastBtnRgt > DebounceTime) {
      lastBtnRgt = millis();
      digitalWrite(Out5, HIGH);  //void RightKey();
    }
  }
  prevBtnRgt = buttonRightState;
}
  
  //Left Button

  if (buttonLeftState == HIGH && prevBtnLft == LOW) {
    if (millis() - lastBtnLft > DebounceTime) {
    lastBtnLft = millis();
    digitalWrite(Out5, LOW);
  }
  }
   prevBtnLft = buttonLeftState;
}













1 Like

Hi

i have posted the copy below

Thanks

C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:16:1: error: expected ',' or ';' before 'const'
 const int inPinUp = A13;
 ^~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:23:1: error: expected ',' or ';' before 'int'
 int prevBtnUp = LOW;
 ^~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:30:1: error: expected unqualified-id before 'unsigned'
 unsigned long lastBtnLft = 0;
 ^~~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino: In function 'void setup()':
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:43:11: error: 'inPinUp' was not declared in this scope
   pinMode(inPinUp, INPUT_PULLUP);
           ^~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:43:11: note: suggested alternative: 'inPinLft'
   pinMode(inPinUp, INPUT_PULLUP);
           ^~~~~~~
           inPinLft
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:46:11: error: 'inPinleft' was not declared in this scope
   pinMode(inPinleft, INPUT_PULLUP);
           ^~~~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:46:11: note: suggested alternative: 'inPinLft'
   pinMode(inPinleft, INPUT_PULLUP);
           ^~~~~~~~~
           inPinLft
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino: In function 'void loop()':
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:105:31: error: 'inPinUp' was not declared in this scope
   buttonUpState = digitalRead(inPinUp);
                               ^~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:105:31: note: suggested alternative: 'inPinLft'
   buttonUpState = digitalRead(inPinUp);
                               ^~~~~~~
                               inPinLft
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:108:33: error: 'inPinLeft' was not declared in this scope
   buttonLeftState = digitalRead(inPinLeft);
                                 ^~~~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:108:33: note: suggested alternative: 'inPinLft'
   buttonLeftState = digitalRead(inPinLeft);
                                 ^~~~~~~~~
                                 inPinLft
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:112:34: error: 'prevBtnUp' was not declared in this scope
     if (buttonUpState == HIGH && prevBtnUp == LOW)
                                  ^~~~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:112:34: note: suggested alternative: 'prevBtnLft'
     if (buttonUpState == HIGH && prevBtnUp == LOW)
                                  ^~~~~~~~~
                                  prevBtnLft
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:131:3: error: 'prevBtnUp' was not declared in this scope
   prevBtnUp = buttonUpState;
   ^~~~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:131:3: note: suggested alternative: 'prevBtnLft'
   prevBtnUp = buttonUpState;
   ^~~~~~~~~
   prevBtnLft
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino: At global scope:
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:167:3: error: expected unqualified-id before 'if'
   if (buttonLeftState == HIGH && prevBtnLft == LOW) {
   ^~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:173:4: error: 'prevBtnLft' does not name a type
    prevBtnLft = buttonLeftState;
    ^~~~~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:174:1: error: expected declaration before '}' token
 }
 ^

exit status 1

Compilation error: expected ',' or ';' before 'const'
1 Like

If you use Auto Format in the IDE you will see that there is something very wrong at the end of the sketch

if (buttonLeftState == HIGH && prevBtnLft == LOW)
{
    if (millis() - lastBtnLft > DebounceTime)
    {
        lastBtnLft = millis();
        digitalWrite(Out5, LOW);
    }
}
prevBtnLft = buttonLeftState;
}

It looks like you have a mismatch between opening and closing braces

The error messages (which you should have included) seem pretty self explanatory.

You're missing a semi colon after your definition of inPinLft, another after your definition of buttonLeftState, you've used a comma rather than a semi colon after your definition of lastBtnLft, inPinleft was never declared (and the compiler even helpfully points out a possible alternative)...

Just read the error messages from the top, fix each one in turn and go from there.

It seems to be with the declarations but i cant find any spelling errors that stands out and the program worked fine until i added the other two buttons in for the left and right key.

Missing ; at end of line.

HI

Thanks guys, i only have a couple of errors left now but cant see what ive missed, cant believe i missed the last ones Lol

C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino: In function 'void setup()':
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:45:11: error: 'inPinleft' was not declared in this scope
   pinMode(inPinleft, INPUT_PULLUP);
           ^~~~~~~~~
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:45:11: note: suggested alternative: 'inPinLeft'
   pinMode(inPinleft, INPUT_PULLUP);
           ^~~~~~~~~
           inPinLeft
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino: At global scope:
C:\Users\RD\Documents\CLS_Controller_v1_2_dev_2023\CLS_Controller_v1_2_dev_2023.ino:163:3: error: expected unqualified-id before 'if'
   if (buttonLeftState == HIGH && prevBtnLft == LOW) {
   ^~

exit status 1

Compilation error: 'inPinleft' was not declared in this scope

See the problem?

Post your revised sketch in a new reply so that we can see the errors in context

Here are your error-messages
CLS_Controller_v1_2_dev_2023.ino:16:1: error: expected ',' or ';' before 'const' const int inPinUp= A13;

CLS_Controller_v1_2_dev_2023.ino:23:1: error: expected ',' or ';' before 'int' int prevBtnUp = LOW;

etc.
filename.ino:23:1:
the 23 is the line-number
the 1 is the columm

best regards Stefan

HI

Ive corrected some of errors you have found and this is the corrected code but only have a couple left now

//4 Aspect CLS controller
//RD
//V1.1
//keys
//left = aspect Down
//Down = aspect off
//UP = Aspect ON
//Right = aspect UP


#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int inPinRight = A12;
const int inPinLeft = A11;
const int inPinUp = A13;
const int inPinDown = A14;
int Aspect = 0;
int buttonUpState = 0;
int buttonDownState = 0;
int buttonRightState = 0;
int buttonLeftState = 0;
int prevBtnUp = LOW;
int prevBtnDwn = LOW;
int prevBtnRgt = LOW;
int prevBtnLft = LOW;
unsigned long lastBtnUp = 0;
unsigned long lastBtnDwn = 0;
unsigned long lastBtnRgt = 0;
unsigned long lastBtnLft = 0;
int DebounceTime = 100;

int Out1 = 24;
int Out2 = 25;
int Out3 = 26;
int Out4 = 27;
int Out5 = A0;



void setup() {
  pinMode(inPinUp, INPUT_PULLUP);
  pinMode(inPinDown, INPUT_PULLUP);
  pinMode(inPinRight, INPUT_PULLUP);
  pinMode(inPinleft, INPUT_PULLUP);
  pinMode(Out1, OUTPUT);
  pinMode(Out2, OUTPUT);
  pinMode(Out3, OUTPUT);
  pinMode(Out4, OUTPUT);
  pinMode(Out5, OUTPUT);

  digitalWrite(Out1, HIGH);  //initial state
  digitalWrite(Out2, HIGH);
  digitalWrite(Out3, HIGH);
  digitalWrite(Out4, HIGH);
  digitalWrite(Out5, HIGH);

  lcd.begin(16, 2);
  lcd.print("CLS  R-Y-G-YY");
}

void AspectFunction() {
  switch (Aspect) {
    case 1:
      lcd.setCursor(2, 1);
      lcd.print("RED      ");
      digitalWrite(Out1, LOW);
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      break;

    case 2:
      lcd.setCursor(0, 1);
      lcd.print("YELL     ");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, LOW);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      break;

    case 3:
      lcd.setCursor(0, 1);
      lcd.print("GREEN      ");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, LOW);
      digitalWrite(Out4, HIGH);
      break;

    case 4:
      lcd.setCursor(0, 1);
      lcd.print("YELL-YELL");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, LOW);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, LOW);
      break;
  }
}

void loop() {

  buttonUpState = digitalRead(inPinUp);
  buttonDownState = digitalRead(inPinDown);
  buttonRightState = digitalRead(inPinRight);
  buttonLeftState = digitalRead(inPinLeft);

  //Up Button

  if (buttonUpState == HIGH && prevBtnUp == LOW) {
    if (millis() - lastBtnUp > DebounceTime) {
      digitalWrite(Out1, HIGH);  //new
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      delay(500);  // new
      Aspect++;

      if (Aspect > 3) {
        Aspect = 4;
      }
      lastBtnUp = millis();
      AspectFunction();
    }
  }
  prevBtnUp = buttonUpState;


  //Down Button

  if (buttonDownState == HIGH && prevBtnDwn == LOW) {
    if (millis() - lastBtnDwn > DebounceTime) {
      digitalWrite(Out1, HIGH);  //new
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      delay(500);  // new
      Aspect--;
      if (Aspect < 1) {
        Aspect = 1;
      }
      lastBtnDwn = millis();
      AspectFunction();
    }
  }
  prevBtnDwn = buttonDownState;


  // Right Button

  if (buttonRightState == HIGH && prevBtnRgt == LOW) {
    if (millis() - lastBtnRgt > DebounceTime) {
      lastBtnRgt = millis();
      digitalWrite(Out5, HIGH);  //void RightKey();
    }
  }
  prevBtnRgt = buttonRightState;
}

//Left Button

  if (buttonLeftState == HIGH && prevBtnLft == LOW) {
    if (millis() - lastBtnLft > DebounceTime) {
    lastBtnLft = millis();
    digitalWrite(Out5, LOW);
  }

prevBtnLft = buttonLeftState;
}

Hi

Thanks for that

  • have added the semicolon but still have an error

const int inPinLeft = A11;

thanks*

This code

//Left Button

if (buttonLeftState == HIGH && prevBtnLft == LOW)
{
    if (millis() - lastBtnLft > DebounceTime)
    {
        lastBtnLft = millis();
        digitalWrite(Out5, LOW);
    }

    prevBtnLft = buttonLeftState;
}

is outside of any function

Hi

i have used the autoformat and used the same code as for the Right button and still have the error for the left also the inpinLeft if you can spot anything

Thanks

See reply #15

Have you correct that problem ?

Hi

I have just spotted what you meant and i only have one error, this is the corrected code so far

//4 Aspect CLS controller
//RD
//V1.1
//keys
//left = aspect Down
//Down = aspect off
//UP = Aspect ON
//Right = aspect UP


#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int inPinRight = A12;
const int inPinLeft = A11;
const int inPinUp = A13;
const int inPinDown = A14;
int Aspect = 0;
int buttonUpState = 0;
int buttonDownState = 0;
int buttonRightState = 0;
int buttonLeftState = 0;
int prevBtnUp = LOW;
int prevBtnDwn = LOW;
int prevBtnRgt = LOW;
int prevBtnLft = LOW;
unsigned long lastBtnUp = 0;
unsigned long lastBtnDwn = 0;
unsigned long lastBtnRgt = 0;
unsigned long lastBtnLft = 0;
int DebounceTime = 100;

int Out1 = 24;
int Out2 = 25;
int Out3 = 26;
int Out4 = 27;
int Out5 = A0;



void setup() {
  pinMode(inPinUp, INPUT_PULLUP);
  pinMode(inPinDown, INPUT_PULLUP);
  pinMode(inPinRight, INPUT_PULLUP);
  pinMode(inPinleft, INPUT_PULLUP);
  pinMode(Out1, OUTPUT);
  pinMode(Out2, OUTPUT);
  pinMode(Out3, OUTPUT);
  pinMode(Out4, OUTPUT);
  pinMode(Out5, OUTPUT);

  digitalWrite(Out1, HIGH);  //initial state
  digitalWrite(Out2, HIGH);
  digitalWrite(Out3, HIGH);
  digitalWrite(Out4, HIGH);
  digitalWrite(Out5, HIGH);

  lcd.begin(16, 2);
  lcd.print("CLS  R-Y-G-YY");
}

void AspectFunction() {
  switch (Aspect) {
    case 1:
      lcd.setCursor(2, 1);
      lcd.print("RED      ");
      digitalWrite(Out1, LOW);
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      break;

    case 2:
      lcd.setCursor(0, 1);
      lcd.print("YELL     ");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, LOW);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      break;

    case 3:
      lcd.setCursor(0, 1);
      lcd.print("GREEN      ");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, LOW);
      digitalWrite(Out4, HIGH);
      break;

    case 4:
      lcd.setCursor(0, 1);
      lcd.print("YELL-YELL");
      digitalWrite(Out1, HIGH);
      digitalWrite(Out2, LOW);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, LOW);
      break;
  }
}

void loop() {

  buttonUpState = digitalRead(inPinUp);
  buttonDownState = digitalRead(inPinDown);
  buttonRightState = digitalRead(inPinRight);
  buttonLeftState = digitalRead(inPinLeft);

  //Up Button

  if (buttonUpState == HIGH && prevBtnUp == LOW) {
    if (millis() - lastBtnUp > DebounceTime) {
      digitalWrite(Out1, HIGH);  //new
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      delay(500);  // new
      Aspect++;

      if (Aspect > 3) {
        Aspect = 4;
      }
      lastBtnUp = millis();
      AspectFunction();
    }
  }
  prevBtnUp = buttonUpState;


  //Down Button

  if (buttonDownState == HIGH && prevBtnDwn == LOW) {
    if (millis() - lastBtnDwn > DebounceTime) {
      digitalWrite(Out1, HIGH);  //new
      digitalWrite(Out2, HIGH);
      digitalWrite(Out3, HIGH);
      digitalWrite(Out4, HIGH);
      delay(500);  // new
      Aspect--;
      if (Aspect < 1) {
        Aspect = 1;
      }
      lastBtnDwn = millis();
      AspectFunction();
    }
  }
  prevBtnDwn = buttonDownState;

  // Right Button

  if (buttonRightState == HIGH && prevBtnRgt == LOW) {
    if (millis() - lastBtnRgt > DebounceTime) {
      lastBtnRgt = millis();
      digitalWrite(Out5, HIGH);  //void RightKey();
    }
  }
  prevBtnRgt = buttonRightState;


  //Left Button

  if (buttonLeftState == HIGH && prevBtnLft == LOW) {
    if (millis() - lastBtnLft > DebounceTime) {
      lastBtnLft = millis();
      digitalWrite(Out5, LOW);
    }
  }
  prevBtnLft = buttonLeftState;
}

HI

Thanks everyone

i have no errors now so thanks for everyone's input for this and i will test it on Monday morning

Much appreciated

It sounds like you found the problem with this

  pinMode(inPinleft, INPUT_PULLUP);

Yes

thanks for your help

i had a lower case L instead of an upper case Lol

@southtyne
If you just post this description but
without
exact that sketch that is causing this error
you are loading extra work on the shoulders of your helpers.

Your helpers will have to bring an older sketch into that state that you described.
They will have to correct the typos that you already have corrected.

So make it a personal habit as soon as you have modified a sketch
to post again and again and again and again
exactly that complete sketch
combined
with the error-messages.

Sketch and error-messages as code-sections.
This is the best possible preparation for remotely analysing compiler-errors.

If everything is now working as expected you should mark the thread as solved.

best regards Stefan