Go Down

Topic: LCD Scroll Menu, with Encoder (Read 1 time) previous topic - next topic

Nicole1998

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.
Code: [Select]

// 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
};


Delta_G

#1
Dec 06, 2017, 05:01 am Last Edit: Dec 06, 2017, 05:03 am by Delta_G
Wow, you really gave us the important part of that code didn't you. 

https://forum.arduino.cc/index.php?topic=353045.0

and the implementation for rotary encoder
http://forum.arduino.cc/index.php?topic=358066.0
If at first you don't succeed, up - home - sudo - enter.

Nicole1998

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

Nicole1998

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

Code: [Select]

#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));
}


Delta_G

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


That sure is a long winded way to say:

Code: [Select]
void cursorSelect(){
  cursorLayer = currentSelect - 1;
}
       
 




If you want anyone to be able to help you, you must describe the problem.  What is it that this code does?  What is it that you want it to do?  How do those two things differ? 
If at first you don't succeed, up - home - sudo - enter.

Nicole1998

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,.

Code: [Select]

 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.

Delta_G

#6
Dec 06, 2017, 06:21 am Last Edit: Dec 06, 2017, 06:23 am by Delta_G
Why is this so hard for folks to understand that you have to communicate the problem.  You're not the only one who just doesn't get this.  Is common sense really that dead?

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,.
and the problem is that the code I have doesn't print the cursor.

OR

and the problem is that this code doesn't move the cursor.

OR

and the problem is that this code opened a vortex to another dimension



What is the problem?  Simple question.  This code does something.  But that isn't what you want.  You have to fill me in on what those two things are. 
If at first you don't succeed, up - home - sudo - enter.

Nicole1998

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)


Code: [Select]

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.

Code: [Select]

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:
Code: [Select]

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();

}

Delta_G

#8
Dec 06, 2017, 06:52 am Last Edit: Dec 06, 2017, 06:53 am by Delta_G
And this code doesn't do that?  What does it do that is different? 

You've done a great job at explaining what you want it to do.  But if you can't describe also the problem with it then you are going to be stuck. 

Maybe let me dumb it down a little more for you. 

Fill in the blanks:

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

I think the first blank you've covered pretty well.  It's that second blank that you've got to fill in.
If at first you don't succeed, up - home - sudo - enter.

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.

artisticforge

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.

Delta_G

Re #9.   Now we're getting somewhere.  So what encoder library are you using.  Look carefully at the documentation for it.  What specifically does the read method in that class return?  Does it returns running count or does it return the movement since the last read? 

Have you played with any of the examples from that library?   Do they seem to work as advertised? 
If at first you don't succeed, up - home - sudo - enter.

Nicole1998

#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.

Delta_G

#include <Encoder.h> /// Arduino encoder.
No, that's the line where you included it.  But there are lots of libraries out there and many have the same name.  When I ask which one you have, I mean specifically.  Like where did you get it?


This is the One I'm using, I have try out some of the library and they seem to work great.
You mean you've tried some of the examples?  Have you looked at the code in them?  Can you pick apart how they work?


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.
No, that's what some whole complete program does.  The read method on that encoder class surely doesn't print anything to the serial monitor.  What does that method return?  Have you looked at the documentation for it?  Have you looked at the code for it? 
If at first you don't succeed, up - home - sudo - enter.

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.

Go Up