Calling function from setup problem

Hello
When attempting compile i'm getting "'printLCD' was not declared in this scope"
It does exist. It doesn't use any milli timers etc

Code is Someone Elses i've modified(barely). They don't say the exact library they use but im pretty sure its the same one..

Ran into another issue with attempted compile on line 53 where lcd.begin(); wasn't a valid call.
Looked up the library i was using and changed to lcd.init(); to get compile to pass.

//20x4 LCD
#include <LiquidCrystal_I2C.h> //SDA = A4, SCL = A5 Arduino https://www.arduino.cc/reference/en/libraries/liquidcrystal-i2c/
LiquidCrystal_I2C lcd(0x27, 20, 4);

int menuCounter = 0; //counts the clicks of the rotary encoder between menu items (0-3 in this case)

int menu1_Value = 0; //value within menu 1
int menu2_Value = 0; //value within menu 2
int menu2_StoredValue = 0; // STORED VALUE FOR COMPARRISSON
int menu3_Value = 0; //value within menu 3
int menu3_StoredValue = 0; // STORED VALUE FOR COMPARRISSON
int menu4_Value = 0; //value within menu 4

bool menu1_selected = false; //enable/disable to change the value of menu item
bool menu2_selected = false;
bool menu3_selected = false;
bool menu4_selected = false;
//Note: if a menu is selected ">" becomes "X".

//Defining pins
//Arduino interrupt pins: 2, 3.
const int RotaryCLK = PB3; //CLK pin on the rotary encoder
const int RotaryDT = PB4; //DT pin on the rotary encoder
const int PushButton = PB5; //Button to enter/exit menu

//Statuses for the rotary encoder
int CLKNow;
int CLKPrevious;

int DTNow;
int DTPrevious;

bool refreshLCD = true; //refreshes values
bool refreshSelection = false; //refreshes selection (> / X)

  // HE Sensor code
  // HE Sensor code
#define DETECT 2 // pin 2 for  sensor (D2)
#define ACTION 8 // pin 8 for action to do someting (A1)

  // HE Sensor code
  // HE Sensor code
const int redRELAY_PIN = 11;  //
const int greyRELAY_PIN = 12;  //

void setup() 
{
  pinMode(PB3, INPUT_PULLUP); //RotaryCLK
  pinMode(PB4, INPUT_PULLUP); //RotaryDT
  pinMode(PB5, INPUT_PULLUP); //Button

  //------------------------------------------------------
  lcd.init();///lcd.begin();  not known in library                    // initialize the lcd   
  lcd.backlight();
  //------------------------------------------------------
  lcd.setCursor(0,0); //Defining positon to write from first row, first column .
  lcd.print("Menu demo");
  lcd.setCursor(0,1); //Second row, first column
  lcd.print("Rotary encoder"); 
  lcd.setCursor(0,2); //Second row, first column
  lcd.print("Improved version"); 
  delay(5000); //wait 2 sec
  
  lcd.clear(); //clear the whole LCD
  
  printLCD(); //print the static parts on the screen
  //------------------------------------------------------
  //Store states of the rotary encoder
  CLKPrevious = digitalRead(RotaryCLK);
  DTPrevious = digitalRead(RotaryDT);
      
  attachInterrupt(digitalPinToInterrupt(RotaryCLK), rotate, CHANGE); //CLK pin is an interrupt pin
  attachInterrupt(digitalPinToInterrupt(PushButton), pushButton, FALLING); //PushButton pin is an interrupt pin
  
  // HE Sensor code
  // HE Sensor code
  /// Serial.println("Hall Module Test"); ///TESTING///
  pinMode(DETECT, INPUT);//define detect input pin
  pinMode(ACTION, OUTPUT);//define ACTION output pin
  // HE Sensor code
  // HE Sensor code
  
  pinMode(redRELAY_PIN, OUTPUT);
  pinMode(greyRELAY_PIN, OUTPUT);

  digitalWrite(greyRELAY_PIN, LOW);//RepeatNotColourChanger
  digitalWrite(redRELAY_PIN, LOW);
}

void loop() 
{
  if(refreshLCD == true) //If we are allowed to update the LCD ...
  {
    updateLCD(); // ... we update the LCD ...

    //... also, if one of the menus are already selected...
    if(menu1_selected == true || menu2_selected == true || menu3_selected == true || menu4_selected == true)
    {
     // do nothing
    }
    else
    {
      updateCursorPosition(); //update the position
    }
    
    refreshLCD = false; //reset the variable - wait for a new trigger
  }

  if(refreshSelection == true) //if the selection is changed
  {
    updateSelection(); //update the selection on the LCD
    refreshSelection = false; // reset the variable - wait for a new trigger
  }
}

void rotate()
{  
  //-----MENU1--------------------------------------------------------------
  if(menu1_selected == true)
  {
  CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
  // If last and current state of CLK are different, then a pulse occurred  
  if (CLKNow != CLKPrevious  && CLKNow == 1)
  {
    // If the DT state is different than the CLK state then
    // the encoder is rotating in A direction, so we increase
    if (digitalRead(RotaryDT) != CLKNow) 
    {
      if(menu1_Value < 9999) //we do not go above 9999
      {
        menu1_Value++;  
      }
      else
      {
        menu1_Value = 0;  
      }      
    } 
    else 
    {
      if(menu1_Value < 0) //we do not go below 0
      {
          menu1_Value = 9999;
      }
      else
      {
      // Encoder is rotating B direction so decrease
      menu1_Value--;      
      }      
    }    
  }
  CLKPrevious = CLKNow;  // Store last CLK state
  }
  //---MENU2---------------------------------------------------------------
  else if(menu2_selected == true)
  {
    CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
  // If last and current state of CLK are different, then a pulse occurred  
  if (CLKNow != CLKPrevious  && CLKNow == 1)
  {
    // If the DT state is different than the CLK state then
    // the encoder is rotating in A direction, so we increase
    if (digitalRead(RotaryDT) != CLKNow) 
    {
      if(menu2_Value < 9999) //we do not go above 9999
      {
        menu2_Value++;  
      }
      else
      {
        menu2_Value = 0;  
      }      
    } 
    else 
    {
      if(menu2_Value < 0) //we do not go below 0
      {
          menu2_Value = 9999;
      }
      else
      {
      // Encoder is rotating in B direction, so decrease
      menu2_Value--;      
      }      
    }    
  }
  CLKPrevious = CLKNow;  // Store last CLK state
  }
  //---MENU3--------------------------------------------------------------- X stop at ColourChanger
  else if(menu3_selected == true)
  {
    CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
  // If last and current state of CLK are different, then a pulse occurred  
  if (CLKNow != CLKPrevious  && CLKNow == 1)
  {
    // If the DT state is different than the CLK state then
    // the encoder is rotating in A direction, so we increase
    if (digitalRead(RotaryDT) != CLKNow) 
    {
      if(menu3_Value < 9999) //we do not go above 9999
      {
        menu3_Value++;  
      }
      else
      {
        menu3_Value = 0;  
      }      
    } 
    else 
    {
      if(menu3_Value < 1) //we do not go below 0
      {
          menu3_Value = 9999;
      }
      else
      {
      // Encoder is rotating B direction so decrease
      menu3_Value--;      
      }      
    }    
  }
  CLKPrevious = CLKNow;  // Store last CLK state
  }
  //---MENU4----------------------------------------------------------------START/PAUSE = HALL EFFECT TRIGGER + DECREMENT
  else if(menu4_selected == true)
  {  
    if (menu1_Value != 0)
      {
        lcd.setCursor(1,3); //4th line, 2nd block
        lcd.print("Pause"); //text
          // HE Sensor code
          // HE Sensor code

         int HEreading = digitalRead(DETECT);// read Hall sensor
          if( HEreading == HIGH)
          {
            menu1_Value = menu1_Value - 1;
            HEreading = LOW;
            
            if (menu2_Value != 0)
            { 
              if (menu2_StoredValue == 0)
                  {
                  menu2_StoredValue = menu2_Value
                  }               
              menu2_Value = menu2_Value - 1;
            }
            if (menu3_Value == 0)
            {
             digitalWrite(redRELAY_PIN, LOW); //StopNotColourChanger
             digitalWrite(greyRELAY_PIN, HIGH);
            }
            
            
            if (menu3_Value != 0)
            { 
              if (menu3_StoredValue == 0)
                  {
                  menu3_StoredValue = menu3_Value
                  }    
              menu3_Value = menu3_Value - 1;
            }
            if (menu3_Value == 0)
            {
             digitalWrite(redRELAY_PIN, HIGH); //StopColourChanger
             digitalWrite(greyRELAY_PIN, HIGH);
            }
            delay(150); ////DELAY FOR LIMITING -1 COUNT
          }
        
          // HE Sensor code
          // HE Sensor code
       }
      if (menu1_Value == 0)///RELAY TRIGGER
      {
        lcd.setCursor(1,3); //4th line, 2nd block
        lcd.print("Start"); //text
        digitalWrite(redRELAY_PIN, LOW); //StopNotColourChanger
        digitalWrite(greyRELAY_PIN, HIGH);
      }
  refreshLCD = true;
  }
  CLKPrevious = CLKNow;  // Store last CLK state
  }
  else //MENU COUNTER----------------------------------------------------------------------------
  {
  CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
  // If last and current state of CLK are different, then a pulse occurred  
  if (CLKNow != CLKPrevious  && CLKNow == 1)
  {
    // If the DT state is different than the CLK state then
    // the encoder is rotating in A direction, so we increase
    if (digitalRead(RotaryDT) != CLKNow) 
    {
      if(menuCounter < 3) //we do not go above 3
      {
        menuCounter++;  
      }
      else
      {
        menuCounter = 0;  
      }      
    } 
    else 
    {
      if(menuCounter < 1) //we do not go below 0
      {
          menuCounter = 3;
      }
      else
      {
      // Encoder is rotating CW so decrease
      menuCounter--;      
      }      
    }    
  }
  CLKPrevious = CLKNow;  // Store last CLK state
  }

  //Refresh LCD after changing the counter's value
  refreshLCD = true;
}

void pushButton()
{
  switch(menuCounter)
  {
     case 0:
     menu1_selected = !menu1_selected;  //we change the status of the variable to the opposite
     break;

     case 1:
     menu2_selected = !menu2_selected;
     break;

     case 2:
     menu3_selected = !menu3_selected;
     break;

     case 3:
     menu4_selected = !menu4_selected;
     break;
  } 
  
  refreshLCD = true; //Refresh LCD after changing the value of the menu
  refreshSelection = true; //refresh the selection ("X")
}

void printLCD()                                                        ///MAINMENU NAMING
{
  //These are the values which are not changing the operation
  
  lcd.setCursor(1,0); //1st line, 2nd block
  lcd.print("Rows"); //text
  //----------------------
  lcd.setCursor(1,1); //2nd line, 2nd block
  lcd.print("Stop"); //text
  //----------------------
  lcd.setCursor(1,2); //3rd line, 2nd block
  lcd.print("Colour"); //text
  //----------------------
  lcd.setCursor(1,3); //4th line, 2nd block
  lcd.print("Start"); //text
  //----------------------
  lcd.setCursor(13,0); //1st line, 14th block
  lcd.print("cnt: "); //counts - text
}

void updateLCD()
{  
  lcd.setCursor(17,0); //1st line, 18th block
  lcd.print(menuCounter); //counter (0 to 3)

  lcd.setCursor(9,0); //1st line, 10th block
  if (menu1_Value  <1000) { //hundred
    lcd.print ("0");
    }  
   if (menu1_Value  <100) { //ten
     lcd.print ("0");
    }
   if (menu1_Value  <10) { //one
     lcd.print ("0");
    }    
   if (menu1_Value  ==0) { //zero
     lcd.print ("0");
    }        
  lcd.print(menu1_Value); //print the value of menu1_Value variable

  lcd.setCursor(9,1);
  if (menu2_Value  <1000) { //hundred
    lcd.print ("0");
    }  
   if (menu2_Value  <100) { //ten
     lcd.print ("0");
    }
   if (menu2_Value  <10) { //one
     lcd.print ("0");
    }    
   if (menu2_Value  ==0) { //zero
     lcd.print ("0");
    }
  lcd.print(menu2_Value); //
  
  lcd.setCursor(9,2);
  if (menu3_Value  <1000) { //hundred
    lcd.print ("0");
    }  
   if (menu3_Value  <100) { //ten
     lcd.print ("0");
    }
   if (menu3_Value  <10) { //one
     lcd.print ("0");
    }    
   if (menu3_Value  ==0) { //zero
     lcd.print ("0");
    }
  lcd.print(menu3_Value); //

  lcd.setCursor(9,3);
  lcd.print(menu4_Value); //  
}

void updateCursorPosition()
{
  //Clear display's ">" parts 
  lcd.setCursor(0,0); //1st line, 1st block
  lcd.print(" "); //erase by printing a space
  lcd.setCursor(0,1);
  lcd.print(" "); 
  lcd.setCursor(0,2);
  lcd.print(" "); 
  lcd.setCursor(0,3);
  lcd.print(" "); 
     
  //Place cursor to the new position
  switch(menuCounter) //this checks the value of the counter (0, 1, 2 or 3)
  {
    case 0:
    lcd.setCursor(0,0); //1st line, 1st block
    lcd.print(">"); 
    break;
    //-------------------------------
    case 1:
    lcd.setCursor(0,1); //2nd line, 1st block
    lcd.print(">"); 
    break;
    //-------------------------------    
    case 2:
    lcd.setCursor(0,2); //3rd line, 1st block
    lcd.print(">"); 
    break;
    //-------------------------------    
    case 3:
    lcd.setCursor(0,3); //4th line, 1st block
    lcd.print(">"); 
    break;
  }
}

void updateSelection()
{
  //When a menu is selected ">" becomes "X"

  if(menu1_selected == true)
  {
    lcd.setCursor(0,0); //1st line, 1st block
    lcd.print("X"); 
  }
  //-------------------
   if(menu2_selected == true)
  {
    lcd.setCursor(0,1); //2nd line, 1st block
    lcd.print("X"); 
  }
  //-------------------
  if(menu3_selected == true)
  {
    lcd.setCursor(0,2); //3rd line, 1st block
    lcd.print("X"); 
  }
  //-------------------
  if(menu4_selected == true)
  {
    lcd.setCursor(0,3); //4th line, 1st block
    lcd.print("X"); 
  }
}

You have an extra closing bracket "}"...

    refreshLCD = true;
  }  // <<<< Not required
  CLKPrevious = CLKNow;  // Store last CLK state
}
else

The are also a couple of ";" missing.

1 Like

Make sure you have the correct library installed... there are multiple with the same name.

There are several libraries with the name LiquidCrystal_I2C. The are not all the same and code from 1 may not run in another. Those LiquidCrystal_I2C libraries are old and most are not maintained. The newest and best library for I2C LCD with the hd44780 controller (1602, 2004) is the hd44780 library by Bill Perry. The hd44780 library automatically detects the I2C address and the LCD to I2C backpack pin mapping. The library is available via the IDE library manager. It is very easy to change code written for a LiquidCrystal_I2C library to use the better hd44780 library.

Any decent way of actually finding out which library this could be? I always thought library #include names had to be unique to be added to the library browser?

Uhh i do believe that closing bracket is required for the start of the nested if statements?
Got a line you found it on? 281?
I do wish Arduino IDE has collapsable nesting like notepad++. Makes checking so much easier
!It now compiles TYVM!

Got those missing ; tyvm.

//20x4 LCD
#include <LiquidCrystal_I2C.h> //SDA = A4, SCL = A5 Arduino https://www.arduino.cc/reference/en/libraries/liquidcrystal-i2c/
LiquidCrystal_I2C lcd(0x27, 20, 4);

int menuCounter = 0; //counts the clicks of the rotary encoder between menu items (0-3 in this case)

int menu1_Value = 0; //value within menu 1
int menu2_Value = 0; //value within menu 2
int menu2_StoredValue = 0; // STORED VALUE FOR COMPARRISSON
int menu3_Value = 0; //value within menu 3
int menu3_StoredValue = 0; // STORED VALUE FOR COMPARRISSON
int menu4_Value = 0; //value within menu 4

bool menu1_selected = false; //enable/disable to change the value of menu item
bool menu2_selected = false;
bool menu3_selected = false;
bool menu4_selected = false;
//Note: if a menu is selected ">" becomes "X".

//Defining pins
//Arduino interrupt pins: 2, 3.
const int RotaryCLK = 2; //CLK pin on the rotary encoder
const int RotaryDT = 4; //DT pin on the rotary encoder
const int PushButton = 3; //Button to enter/exit menu

//Statuses for the rotary encoder
int CLKNow;
int CLKPrevious;

int DTNow;
int DTPrevious;

bool refreshLCD = true; //refreshes values
bool refreshSelection = false; //refreshes selection (> / X)

// HE Sensor code
// HE Sensor code
#define DETECT 5 // pin 5 for  sensor (D5)
#define ACTION 8 // pin 8 for action to do someting (A1)

// HE Sensor code
// HE Sensor code
const int redRELAY_PIN = 11;  //
const int greyRELAY_PIN = 12;  //

void setup()
{
  pinMode(2, INPUT_PULLUP); //RotaryCLK
  pinMode(4, INPUT_PULLUP); //RotaryDT
  pinMode(3, INPUT_PULLUP); //Button

  //------------------------------------------------------
  lcd.init();//lcd.begin(); /// not known in library  lcd.init();///                  // initialize the lcd
  lcd.backlight();
  //------------------------------------------------------
  lcd.setCursor(0, 0); //Defining positon to write from first row, first column .
  lcd.print("Menu demo");
  lcd.setCursor(0, 1); //Second row, first column
  lcd.print("Rotary encoder");
  lcd.setCursor(0, 2); //Second row, first column
  lcd.print("Improved version");
  delay(50); //wait 1 sec

  lcd.clear(); //clear the whole LCD

  printLCD(); //print the static parts on the screen
  //------------------------------------------------------
  //Store states of the rotary encoder
  CLKPrevious = digitalRead(RotaryCLK);
  DTPrevious = digitalRead(RotaryDT);

  attachInterrupt(digitalPinToInterrupt(RotaryCLK), rotate, CHANGE); //CLK pin is an interrupt pin
  attachInterrupt(digitalPinToInterrupt(PushButton), pushButton, FALLING); //PushButton pin is an interrupt pin

  // HE Sensor code
  // HE Sensor code
  /// Serial.println("Hall Module Test"); ///TESTING///
  pinMode(DETECT, INPUT);//define detect input pin
  pinMode(ACTION, OUTPUT);//define ACTION output pin
  // HE Sensor code
  // HE Sensor code

  pinMode(redRELAY_PIN, OUTPUT);
  pinMode(greyRELAY_PIN, OUTPUT);

  digitalWrite(greyRELAY_PIN, LOW);//RepeatNotColourChanger
  digitalWrite(redRELAY_PIN, LOW);
}

void loop()
{
  if (refreshLCD == true) //If we are allowed to update the LCD ...
  {
    updateLCD(); // ... we update the LCD ...

    //... also, if one of the menus are already selected...
    if (menu1_selected == true || menu2_selected == true || menu3_selected == true || menu4_selected == true)
    {
      // do nothing
    }
    else
    {
      updateCursorPosition(); //update the position
    }

    refreshLCD = false; //reset the variable - wait for a new trigger
  }

  if (refreshSelection == true) //if the selection is changed
  {
    updateSelection(); //update the selection on the LCD
    refreshSelection = false; // reset the variable - wait for a new trigger
  }
}

void rotate()
{
  //-----MENU1--------------------------------------------------------------
  if (menu1_selected == true)
  {
    CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
    // If last and current state of CLK are different, then a pulse occurred
    if (CLKNow != CLKPrevious  && CLKNow == 1)
    {
      // If the DT state is different than the CLK state then
      // the encoder is rotating in A direction, so we increase
      if (digitalRead(RotaryDT) != CLKNow)
      {
        if (menu1_Value < 9999) //we do not go above 9999
        {
          menu1_Value++;
        }
        else
        {
          menu1_Value = 0;
        }
      }
      else
      {
        if (menu1_Value < 0) //we do not go below 0
        {
          menu1_Value = 9999;
        }
        else
        {
          // Encoder is rotating B direction so decrease
          menu1_Value--;
        }
      }
    }
    CLKPrevious = CLKNow;  // Store last CLK state
  }
  //---MENU2---------------------------------------------------------------
  else if (menu2_selected == true)
  {
    CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
    // If last and current state of CLK are different, then a pulse occurred
    if (CLKNow != CLKPrevious  && CLKNow == 1)
    {
      // If the DT state is different than the CLK state then
      // the encoder is rotating in A direction, so we increase
      if (digitalRead(RotaryDT) != CLKNow)
      {
        if (menu2_Value < 9999) //we do not go above 9999
        {
          menu2_Value++;
        }
        else
        {
          menu2_Value = 0;
        }
      }
      else
      {
        if (menu2_Value < 0) //we do not go below 0
        {
          menu2_Value = 9999;
        }
        else
        {
          // Encoder is rotating in B direction, so decrease
          menu2_Value--;
        }
      }
    }
    CLKPrevious = CLKNow;  // Store last CLK state
  }
  //---MENU3--------------------------------------------------------------- X stop at ColourChanger
  else if (menu3_selected == true)
  {
    CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
    // If last and current state of CLK are different, then a pulse occurred
    if (CLKNow != CLKPrevious  && CLKNow == 1)
    {
      // If the DT state is different than the CLK state then
      // the encoder is rotating in A direction, so we increase
      if (digitalRead(RotaryDT) != CLKNow)
      {
        if (menu3_Value < 9999) //we do not go above 9999
        {
          menu3_Value++;
        }
        else
        {
          menu3_Value = 0;
        }
      }
      else
      {
        if (menu3_Value < 1) //we do not go below 0
        {
          menu3_Value = 9999;
        }
        else
        {
          // Encoder is rotating B direction so decrease
          menu3_Value--;
        }
      }
    }
    CLKPrevious = CLKNow;  // Store last CLK state
  }
  //---MENU4----------------------------------------------------------------START/PAUSE = HALL EFFECT TRIGGER + DECREMENT
  else if (menu4_selected == true)
  {
    if (menu1_Value != 0)
    {
      lcd.setCursor(1, 3); //4th line, 2nd block
      lcd.print("Pause"); //text
      // HE Sensor code
      // HE Sensor code

      int HEreading = digitalRead(DETECT);// read Hall sensor
      if ( HEreading == HIGH)
      {
        menu1_Value = menu1_Value - 1;
        HEreading = LOW;

        if (menu2_Value != 0)
        {
          if (menu2_StoredValue == 0)
          {
            menu2_StoredValue = menu2_Value;
          }
          menu2_Value = menu2_Value - 1;
        }
        if (menu3_Value == 0)
        {
          digitalWrite(redRELAY_PIN, LOW); //StopNotColourChanger
          digitalWrite(greyRELAY_PIN, HIGH);
        }


        if (menu3_Value != 0)
        {
          if (menu3_StoredValue == 0)
          {
            menu3_StoredValue = menu3_Value;
          }
          menu3_Value = menu3_Value - 1;
        }
        if (menu3_Value == 0)
        {
          digitalWrite(redRELAY_PIN, HIGH); //StopColourChanger
          digitalWrite(greyRELAY_PIN, HIGH);
        }
        delay(150); ////DELAY FOR LIMITING -1 COUNT
      }

      // HE Sensor code
      // HE Sensor code
    }
    if (menu1_Value == 0)///RELAY TRIGGER
    {
      lcd.setCursor(1, 3); //4th line, 2nd block
      lcd.print("Start"); //text
      digitalWrite(redRELAY_PIN, LOW); //StopNotColourChanger
      digitalWrite(greyRELAY_PIN, HIGH);
    }
    refreshLCD = true;
  
  CLKPrevious = CLKNow;  // Store last CLK state
}
else //MENU COUNTER----------------------------------------------------------------------------
{
  CLKNow = digitalRead(RotaryCLK); //Read the state of the CLK pin
  // If last and current state of CLK are different, then a pulse occurred
  if (CLKNow != CLKPrevious  && CLKNow == 1)
  {
    // If the DT state is different than the CLK state then
    // the encoder is rotating in A direction, so we increase
    if (digitalRead(RotaryDT) != CLKNow)
    {
      if (menuCounter < 3) //we do not go above 3
      {
        menuCounter++;
      }
      else
      {
        menuCounter = 0;
      }
    }
    else
    {
      if (menuCounter < 1) //we do not go below 0
      {
        menuCounter = 3;
      }
      else
      {
        // Encoder is rotating CW so decrease
        menuCounter--;
      }
    }
  }
  CLKPrevious = CLKNow;  // Store last CLK state
}

//Refresh LCD after changing the counter's value
refreshLCD = true;
}

void pushButton()
{
  switch (menuCounter)
  {
    case 0:
      menu1_selected = !menu1_selected;  //we change the status of the variable to the opposite
      break;

    case 1:
      menu2_selected = !menu2_selected;
      break;

    case 2:
      menu3_selected = !menu3_selected;
      break;

    case 3:
      menu4_selected = !menu4_selected;
      break;
  }
  delay(100); /// STOPS DEBOUNCING!!!
  refreshLCD = true; //Refresh LCD after changing the value of the menu
  refreshSelection = true; //refresh the selection ("X")
}

void printLCD()                                                        ///MAINMENU NAMING
{
  //These are the values which are not changing the operation

  lcd.setCursor(1, 0); //1st line, 2nd block
  lcd.print("Rows"); //text
  //----------------------
  lcd.setCursor(1, 1); //2nd line, 2nd block
  lcd.print("Stop"); //text
  //----------------------
  lcd.setCursor(1, 2); //3rd line, 2nd block
  lcd.print("Colour"); //text
  //----------------------
  lcd.setCursor(1, 3); //4th line, 2nd block
  lcd.print("Start"); //text
  //----------------------
  lcd.setCursor(13, 0); //1st line, 14th block
  lcd.print("cnt: "); //counts - text
}

void updateLCD()
{
  lcd.setCursor(17, 0); //1st line, 18th block
  lcd.print(menuCounter); //counter (0 to 3)

  lcd.setCursor(9, 0); //1st line, 10th block
  if (menu1_Value  < 1000) { //hundred
    lcd.print ("0");
  }
  if (menu1_Value  < 100) { //ten
    lcd.print ("0");
  }
  if (menu1_Value  < 10) { //one
    lcd.print ("0");
  }
  if (menu1_Value  == 0) { //zero
    lcd.print ("0");
  }
  lcd.print(menu1_Value); //print the value of menu1_Value variable

  lcd.setCursor(9, 1);
  if (menu2_Value  < 1000) { //hundred
    lcd.print ("0");
  }
  if (menu2_Value  < 100) { //ten
    lcd.print ("0");
  }
  if (menu2_Value  < 10) { //one
    lcd.print ("0");
  }
  if (menu2_Value  == 0) { //zero
    lcd.print ("0");
  }
  lcd.print(menu2_Value); //

  lcd.setCursor(9, 2);
  if (menu3_Value  < 1000) { //hundred
    lcd.print ("0");
  }
  if (menu3_Value  < 100) { //ten
    lcd.print ("0");
  }
  if (menu3_Value  < 10) { //one
    lcd.print ("0");
  }
  if (menu3_Value  == 0) { //zero
    lcd.print ("0");
  }
  lcd.print(menu3_Value); //

  lcd.setCursor(9, 3);
  lcd.print(menu4_Value); //
}

void updateCursorPosition()
{
  //Clear display's ">" parts
  lcd.setCursor(0, 0); //1st line, 1st block
  lcd.print(" "); //erase by printing a space
  lcd.setCursor(0, 1);
  lcd.print(" ");
  lcd.setCursor(0, 2);
  lcd.print(" ");
  lcd.setCursor(0, 3);
  lcd.print(" ");

  //Place cursor to the new position
  switch (menuCounter) //this checks the value of the counter (0, 1, 2 or 3)
  {
    case 0:
      lcd.setCursor(0, 0); //1st line, 1st block
      lcd.print(">");
      break;
    //-------------------------------
    case 1:
      lcd.setCursor(0, 1); //2nd line, 1st block
      lcd.print(">");
      break;
    //-------------------------------
    case 2:
      lcd.setCursor(0, 2); //3rd line, 1st block
      lcd.print(">");
      break;
    //-------------------------------
    case 3:
      lcd.setCursor(0, 3); //4th line, 1st block
      lcd.print(">");
      break;
  }
}

void updateSelection()
{
  //When a menu is selected ">" becomes "X"

  if (menu1_selected == true)
  {
    lcd.setCursor(0, 0); //1st line, 1st block
    lcd.print("X");
  }
  //-------------------
  if (menu2_selected == true)
  {
    lcd.setCursor(0, 1); //2nd line, 1st block
    lcd.print("X");
  }
  //-------------------
  if (menu3_selected == true)
  {
    lcd.setCursor(0, 2); //3rd line, 1st block
    lcd.print("X");
  }
  //-------------------
  if (menu4_selected == true)
  {
    lcd.setCursor(0, 3); //4th line, 1st block
    lcd.print("X");
  }
}

Having fixed the compile problem. I'm having an issue with two things.
1: The push button seems to be bouncing weirdly. Button is NC
Partially solved but adding a delay @ line 343 (Not acceptable fix if i remember correctly)

2:When Start menu4_selected the screen/arduino freezes and becomes unresponsive. What have i forgotten...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.