Using the 2x16 LCD to control things

Hello,

I am wondering if anyone has created something that uses the LCD as a interface with buttons to control simple things? for example select different lights to turn them off or on? is it possible to do this?

It is certainly possible to do this. Use the LCD to display options and pushbuttons to move through the options and select and activate actions.

What have you done so far ?
Do you know how to read the state of a pushbutton and act differently according to whether it is pressed or not ?
Do you know how to display text on the LCD ?

There are menu libraries for use with LCDs but you probably do not need that complication.

I can display text on the LCD, how does the arduino know what you are selecting on the LCD? so if there is a list of 5 different LED's to select from how does it know which one you have chosen?

and yes I can read the state of the push button.

I can display text on the LCD, how does the arduino know what you are selecting on the LCD?

How can you select something on an LCD? Are pushing on some text?

You would display some text like:

Select led:
1 2 3 4 5

and expect the user (you) to be smart enough to understand that that meant to press switch 1 or 2 or 3 or 4 or 5.

and yes I can read the state of the push button.

Well, then, you can determine what the user selected.

I wanted to have 3 push buttons control the LCD, two for up and down to scroll through the different LED's and one to select on or off on the selected LED

I wanted to have 3 push buttons control the LCD, two for up and down to scroll through the different LED's and one to select on or off on the selected LED

Permission granted. Proceed.

was just asking if this was possible? and maybe some tips on how I could go about this :stuck_out_tongue:

was just asking if this was possible?

Of course it is.

and maybe some tips on how I could go about this

What do you need help with? Can you display text on the LCD? Well, there is the menu.

Can you read whether a switch is pressed? If switch one is pressed, the user wants option 1. If switch 2 is pressed, the user wants option 2. The same story applies to the other 3 switches/options.

I was hopping to have a scroll menu, so instead of just having 1 button per LED I wanted to scroll through and select the LED then go to a sub menu (one for each LED) and select weather to turn it on or off or go back to the main menu. my main question is how would I get the arduino to change the LED pinout according to what is selected on the LCD.

my main question is how would I get the arduino to change the LED pinout according to what is selected on the LCD.

You can't. Your question does not make sense. You connected an LED to a pin. Why would that change? Why would you offer the user to option to move the LED on pin 5 to some other pin?

Sorry I ment the pinout state eg on or off

You have never developed a user interface, have you? You are taking a big jump trying to make a user interface with so little understanding.

A menu is a list of choices. Displaying a menu is easy. Understanding what was picked is easy. Changing the state of the program is the more difficult task.

This can involve displaying another menu or taking some action and moving back to a previous menu.

The only way to learn how to do this is to get started. Initially, limit your menus to what can be displayed on one screen. Fancy crap like scrolling a menu comes later. Limit your self to one submenu per main menu item.

Try something. You might be amazed that it is not a difficult as you think. Or, you may realize that you need a completely different way of controlling what the Arduino does. A PC application with much fancier forms and menus comes to mind.

Okay I will start by just having two different options displayed on the screen, Do I then need to create a cursor to move between these two options?

peter86:
I was hopping to have a scroll menu, so instead of just having 1 button per LED I wanted to scroll through and select the LED then go to a sub menu (one for each LED) and select weather to turn it on or off or go back to the main menu. my main question is how would I get the arduino to change the LED pinout according to what is selected on the LCD.

I suggest that you keep things simple.
Suppose that you have 4 LEDs known as LED[0] to LED[3]
Set a counter to 0 then call a function with the counter as a parameter. The function should display text to indicate the currently selected LED. Do this in the setup() function. Then in the loop() function read the input from a pushbutton. When it becomes pressed (not when it IS pressed) increment the counter(reset it to zero if it reaches 4) and call the function to change the LCD display.

Do nothing more to start with but you can probably see that the value of the counter variable will allow the program to know which LED is currently selected.

Knowledge needed to implement this :
How to read an input and act on its value
How to spot that an input has changed from HIGH to LOW or vice-versa. See the StateChangeDetection example in the IDE
How to display different information on the LCD depending on the value of a variable. Using arrays will make this much easier. Read up on them is they are new to you.

Use a variable to hold an integer value; perhaps call it Count. Program so that Count increments or decrements depending on the change of state of the up and down push buttons. Depending on the value of Count, display certain text. For example: If Count is 2, display: "Push 'on' button for led 2". Program so that if Count is 2 & 'on' push button is depressed, drive the pin that led 2 is connected to to an on (dependent on how you have your led wired) condition. Else, drive it to an off condition.

I can display text on the LCD, how does the arduino know what you are selecting on the LCD? so if there is a list of 5 different LED's to select from how does it know which one you have chosen?

By knowing the value of Count.

  • Scotty

How do I set up a counter for the LEDS and get them to display?

How do I set up a counter for the LEDS

byte ledCounter = 0;

and get them to display?

lcd.print("Current LED :");
lcd.print(ledCounter);

Okay this is what I have so far :slight_smile:

the problems I am facing now:

  • is I don’t know how to get the count to not go over 4 and bellow 0
  • and when turning the LED’s of and on I want the code to read there current state, I had a go at it in the bottom part of my code
#include <LiquidCrystal.h>

const int  buttonPin3 = 10;
const int  buttonPin2 = 7;
const int  buttonPin1 = 6;
const int ledPin = 13;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int buttonPushCounter = 0;   
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int lastButtonState1 = 0;
int lastButtonState2 = 0; 


void setup() {
  pinMode(buttonPin1, INPUT);
  
  pinMode(buttonPin2, INPUT);
  
  pinMode(buttonPin3, INPUT);
    
    Serial.begin(9600);

  lcd.begin(16, 2);
  
  pinMode(ledPin, OUTPUT);
 
  lcd.print("LED Menu");
  
  lcd.setCursor(0,1);

}

void loop() {
  
 
  buttonState1 = digitalRead(buttonPin1);

 
 if (buttonState1 != lastButtonState1) {
   
 if (buttonState1 == HIGH) {buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
  lcd.setCursor(7,1);
           
      lcd.print(buttonPushCounter);  
  } 
    else {

      Serial.println("off"); 
    }
  }







  lastButtonState1 = buttonState1;
  
  
  buttonState2 = digitalRead(buttonPin2);


 
   if (buttonState2 != lastButtonState2) {
     

     
     if (buttonState2 == HIGH)
     
     {
       
      buttonPushCounter--;
lcd.setCursor(7,1);
          
      lcd.print(buttonPushCounter);
     }
       
             
   }
   lastButtonState2 = buttonState2; 
   
   
  
  
  
  
  
  
 buttonState3 = digitalRead(buttonPin3);
 
 
 
 if (buttonState3 == HIGH && buttonPushCounter == 2 && ledPin == LOW)

 {
    digitalWrite(ledPin, HIGH);
  }
  else {
   if (buttonState3 == HIGH && buttonPushCounter == 2 && ledPin == HIGH)
   {digitalWrite(ledPin, LOW);}
  }
   
}

It's time that you learned what Tools + Auto Format does.
It's time that you learned to be consistent. Every { goes on a line by itself, or none do. There is no in between.

Excessive

use

of

white

space

is

annoying.

  • and when turning the LED's of and on I want the code to read there current state

Why? You should remember that.