LCD Scroll Menu, with Encoder

Hi I'm trying to make a simple code, Using A LCD screen and a encoder, to scroll through 10 different menu, With a cursor, After moving the cursor to the target, press the button on the encode to turn a false statement true. Then print the different thing the machine is doing until done, then go back to menu? I have been trying all day looking up codes and can't seem to find any. It be greatly appreciate if someone could help.

Thanks Nicole.

// Custom character for LCD.
byte cursor[8] = {
  0b10000,
  0b10000,
  0b01000,
  0b00110,
  0b01000,
  0b10000,
  0b10000,
  0b00000
};

byte watch[8] = {
  0b01110,
  0b01110,
  0b11011,
  0b10001,
  0b10001,
  0b11011,
  0b01110,
  0b01110
};

I do apologize, The code I have been working on is a mess please over look, right now I'

right now I working on getting the cursor to move. This is the code I got

#include "OneButton.h"
#include <Encoder.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
Encoder myEnc(2, 3);
int cursorLayer = 0;
int currentSelect = 1;
int cursorPosition = 0;
int currentPosition = 0;
// Custom character for LCD.
byte cursor[8] = {
  0b10000,
  0b10000,
  0b01000,
  0b00110,
  0b01000,
  0b10000,
  0b10000,
  0b00000
};

byte watch[8] = {
  0b01110,
  0b01110,
  0b11011,
  0b10001,
  0b10001,
  0b11011,
  0b01110,
  0b01110
};
OneButton button1(8, true);
void setup() {
  Serial.begin(9600);
  lcd.begin (20,4);
  lcd.setBacklightPin(3,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home();
pinMode(13, OUTPUT); 
button1.attachClick(singleclick);

lcd.createChar(0, cursor);
lcd.setCursor (2,0);
 cursorLayer = 0;
  lcd.setCursor (0,cursorLayer);  
  writeCursor();
}
long oldPosition  = -999;

void loop() {

  // Listen to button presses.
    button1.tick();


  
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
  newPosition = cursorLayer + 1;
  
if(newPosition > oldPosition){
   lcd.setCursor (0,newPosition);  
        writeCursor();
 
}
if (newPosition <= oldPosition){
    lcd.setCursor (0,newPosition);  
        writeCursor();
  
  }
  /*if(myEnc.read() == 4){
    Serial.println("Drink2");
    lcd.setCursor (0,0);
    lcd.print(" ");
    lcd.setCursor (0,1);
    writeCursor();
  }*/
}
  void singleclick() {
  static int m = LOW;
  // reverse the LED 
  m = !m;
  digitalWrite(13, m);
} // doubleclick
void cursorSelect(){
  switch (currentSelect){
          case 1:
            cursorLayer = 0;
            break;
          case 2:
            cursorLayer = 1;
            break;
          case 3:
            cursorLayer = 2;
            break;
          case 4:
            cursorLayer = 3;
            break;
        
        }
}
void writeCursor(){
  lcd.write(byte(0));
}

Sure Sorry about that, Umm I need a scroll menu, on this 20x4 LCD screen with 10 different thing a machine can do.

Example:// LCD display

LED1
LED2
LED3
LED4
etc....

If I move the cursor to say LED3, and I push the button(encoder button) I need it make a LED3 true.

everything on the machine is set to false.

the spot I'm in on the code right now is getting the cursor to move up and down with the encoder as show below,.

 long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
  newPosition = currentSelect + 1;
 if(newPosition > oldPosition && currentSelect >= 2){
        clearSelect();
        currentSelect++;
}
if (newPosition < oldPosition && currentSelect <= 2){
       clearSelect();
        currentSelect++;
  }

code line: 60-74

Thanks for the help.

I'm trying my best to communicate with you this best I can.

This is cursor Select, each layer is the the different lines on the LCD screen.

example:
cursorLayer = 1; // This one is to mover the cursor to line 2 one the LCD (With is 1, because it starts with 0)

void cursorSelect(){
  switch (currentSelect){
          case 1:
            cursorLayer = 0;
            break;
          case 2:
            cursorLayer = 1;
            break;
          case 3:
            cursorLayer = 2;
            break;
          case 4:
            cursorLayer = 3;
            break;

This is something i was trying to see if would work.

void cursorSelect(){
  cursorLayer = currentSelect - 1;
}

So far in the code I have got not where, I have never done a Menu/scroll before.

The Problem in the code I'm having is getting the value of the encode to change to get the Cursor to move.

Example:

if(newPosition > oldPosition){           //if the encoder is turned CW, the Cursor Moves down a roll
 lcd.setCursor (0,newPosition);  
        writeCursor();
}
if(newPosition < oldPosition){ 
 lcd.setCursor (0,newPosition - 1);   //if the encoder is turned CCW, the Cursor Moves up a roll
        writeCursor();

}

I want this code to _1 but it doesn't. Instead it _2 and that's not what I want.

  1. I want the cursor to move up and down on the left side of the 20x4 LCD screen.

  2. It will not move the cursor down or back up, I can't get the values of the encode to to change with the cursor to move it. The cursor is staying in (0,0) plan.

Nicole1998:
I want this code to _1 but it doesn't. Instead it _2 and that's not what I want.

  1. I want the cursor to move up and down on the left side of the 20x4 LCD screen.

  2. It will not move the cursor down or back up, I can't get the values of the encode to to change with the cursor to move it. The cursor is staying in (0,0) plan.

I would suggest that you look at the examples for the Arduino Explora.
The Explora is basically an Arduino Leonardo with a joystick, 4 buttons and a small LCD display.
The Etch-A-Sketch example may be worth looking at.

It is 0242 here so I will look up some more examples in the morning when I am wide awake.

Welcome to the world of Arduino.
A new adventure everyday.

#include <Encoder.h> /// Arduino encoder.

This is the One I'm using, I have try out some of the library and they seem to work great.

As far as read method, in the serial port, the value(on Base Example) Starts at 0 and goes up and down as I turn the encode(prints one Line as I turn). if I stop turning it, it stops at the line with that value.

I really appreciate your time, But I have tried everything to understand how to make this, I've seem a lot of code for menu and all of them have a sub screen which I don't need, I have spend several hours in front of the computer trying different thing to make any of the code i get work and trying to understand how they work I'm just not understand it. I'm trying my best to give you what I know so you can help me.

I think it be easier for both of us to start over, You need to know the encoder I'm using and I'm not for sure with one, I know I download it from the library, But if you know of one off the top of your head we can work with lets try that so we are on the same page.

I do apologize for not know how to do, I never done encoder or menu on LCD screen before. Mostly all i have done is use them to display message of machine.

As you know I have a Encode and 20x4 LCD display with the IC2 backpack. I need a menu that I can scroll through and pick what I want the machine to.

Display exmaple:

LED1
LED2
LED3
LED4
Etc.

After scrolling though and finding the LED I want to use. I will then click the encode(singleClick). It will turn the LED that I pick to true.

Example: Scroll down to >LED8
Click the Encoder.
LED8 = true.
After it done runnning the code.
LED8 = false.
return the Menu back to LED.

I'm asking for you help in Pretty much everything in Writing this code because I haven't got anywhere.
I haven't learned anything.

I really hope you can help me because I have worked so hard in the project and this is the last thing I need for it to be done.

If you like to Private message me I can give you my email.

Nicole1998:
I really appreciate your time, But I have tried everything to understand how to make this, I've seem a lot of code for menu and all of them have a sub screen which I don't need, I have spend several hours in front of the computer trying different thing to make any of the code i get work and trying to understand how they work I'm just not understand it. I'm trying my best to give you what I know so you can help me.

I think it be easier for both of us to start over, You need to know the encoder I'm using and I'm not for sure with one, I know I download it from the library, But if you know of one off the top of your head we can work with lets try that so we are on the same page.

I do apologize for not know how to do, I never done encoder or menu on LCD screen before. Mostly all i have done is use them to display message of machine.

As you know I have a Encode and 20x4 LCD display with the IC2 backpack. I need a menu that I can scroll through and pick what I want the machine to.

Display exmaple:

LED1
LED2
LED3
LED4
Etc.

After scrolling though and finding the LED I want to use. I will then click the encode(singleClick). It will turn the LED that I pick to true.

Example: Scroll down to >LED8
Click the Encoder.
LED8 = true.
After it done runnning the code.
LED8 = false.
return the Menu back to LED.

I'm asking for you help in Pretty much everything in Writing this code because I haven't got anywhere.
I haven't learned anything.

I really hope you can help me because I have worked so hard in the project and this is the last thing I need for it to be done.

If you like to Private message me I can give you my email.

Allow me to help you.
Would you mind restating your problem/project?

I will try my best to provide you with a workable solution.
Being frustrated does no one any good.
It turns you (generic you) off programming and arduino.
I will read your posts in the morning and go through the background.

Alright So I have a machine that has 10 different thing it can do. All the thing are set to false in the program until I Press a button, I would like to change the buttons so I don't need 10 of them.

I need the button on the encoder and the LCD display to change (int) to true. After it runs through the code, at the end I have it setting the (int) back to false so i can run something else.

I buy a encoder, and a 20x4 LCD display to take place of the buttons.

I would like to have a scroll menu with a cursor that scroll down the left side of the LCD screen till I get to the function I would like to run.

I have no code for it, I have try multiple menu codes and all of them are using different layers and changing values.

All I need is a menu(1 Layer). and as I scroll the Encode I need the cursor to move down the LCD display until I get to what I want to run.

If i press down on the encoder(single Click). The menu will go away and the LCD Display will print what the machine is doing until it is done. After its done it will return to the Menu to start over. (NO Values to change, no Sub menu inside menus, just ONE layer).

I have searched and couldn't find anyone that has done anything like this, I though it was going to be a little easier then what i have been though to get this to work.

The one I posted in reply #1 will work with any number of screens. It is probably a little more complex than what you are after, but really all you'd have to do is switch out the LCD library to the one you use and write all of the functions to light the light and return true.

I have try download it but I can't find the library to? do you have a link?

I have when back through everything, I when back to the Link you send to me using MenuClass, I got the libeary and I have try to use it and it throws Error fun1 is not in scope.
I think I understand a little bit more now and I might be about to get this code to work. But I'm not sure on the Error.
Any Ideas?

Did you make the modifications that it needs? Did you read the part where I said it probably wasn't what you needed?

I didn't know anything need to be changed just to get it upload? I known that i need to add the LCD screen but I was just going to see how it worked with the serial to get a understand?

I couldn't fine anywhere that need to change something?