Go Down

Topic: Changing screens with buttons  (Read 182 times) previous topic - next topic

LukeOliver2001

Hi all,
I'm trying to figure out how to change screens/ change the text on the screen. Basically i can't use Liquid crystal because ii can't get it to connect with my LCD so I'm having to use wire.h for everything. i need to be able to press the button once and it stays on the next screen rather than having to hold it down all the time because i want it as a skip to next page kinda thing. The way the buttons are wired up is 5v one side of the button and ground with a 10k resistor is joined with digital pin 11. I can get it showing up however, both messages come up together rather than one being always on until i press the button and when I let go it goes back to a blank screen where i need it to stay on the next page.
- thanks





Code: [Select]
#include <Wire.h>

#define LCD05  0x63                   // LCD05 address

char stringBuf[20];
byte buffer[4];
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 11;     // the number of the pushbutton pin


// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  delay(100);                          // Delay to wait for everything to power up
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  Wire.begin();
 
  buffer[0] = 0;                       // Clear the screen
  buffer[1] = 12;
  buffer[2] = 19;
  buffer[3] = 31;
  buffer[4] = 10;
 
 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
}

void loop() {
 // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is LOW:
  if (buttonState == LOW) {

   
 digitalWrite(buttonPin, HIGH);
 Wire.begin();
  buffer[1] = 12; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,2);
  Wire.endTransmission();
   
   
   Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 2;
  buffer[4] = 3; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
    delay(100);
 String message1 = "  {SELECT FORCE}";      // The message to be put on the screen
  int len1 = message1.length() + 1;       // Length of the message
  message1.toCharArray(stringBuf, len1);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len1);
  Wire.endTransmission();

  }else{
 digitalWrite(buttonPin, LOW);

 

delay(100);
   Wire.begin();
  buffer[1] = 19;
  buffer[2] = 3;
  buffer[3] = 4;
  buffer[4] = 3; 
  Wire.beginTransmission(LCD05);
  Wire.write(buffer,5);
  Wire.endTransmission();
 
   
 String message2 = "  {running}";      // The message to be put on the screen
  int len2 = message2.length() + 1;       // Length of the message
  message2.toCharArray(stringBuf, len2);  // Convert the message to a car array
  stringBuf[0] = 0;                     // First byte of message to 0 (LCD05 command register)
  Wire.beginTransmission(LCD05);
  Wire.write(stringBuf, len2);
  Wire.endTransmission();
  }
}

6v6gt

#1
Nov 08, 2019, 11:36 am Last Edit: Nov 08, 2019, 11:40 am by 6v6gt
First your problems which force you to use the Wire library directly to interface to the screen.
What screen is it ? The I2C address appears unusual. For example, an LCD1602 display with backpack  normally has the I2C address of 0x27 or 0x3F (although you can select other addresses with a solder jumper. The matching library would be LiquidCrystal_I2C.h.

If your goal is to have a single button press which changes the contents displayed on the screen, and those contents remain until the next button press, then you have to maintain a variable indicating the button state (or the state of the screen display). This variable controls what is displayed on the screen. Something like:


Code: [Select]

// pseudocode:

int buttonState = 0 ;

loop() {

  if button pressed increment buttonState (debounce here)
  if buttonState rollover reached, set buttonState to 0.

  if ( buttonState == 0 ) {
     show blank screen
  }
  else of ( buttonState == 1 ) {
     show menu1
  }
  else of ( buttonState == 2 ) {
     show menu2
  }

}

LukeOliver2001

I'm using a Daventech I2C LCD05. I've done multiple tests because i was coming to the same conclusion with the Address being completely different but it's actually 0x63

6v6gt

#3
Nov 08, 2019, 12:19 pm Last Edit: Nov 08, 2019, 12:38 pm by 6v6gt
OK. I've never seen that before: https://www.robot-electronics.co.uk/htm/Lcd05tech.htm

I'm curious to know what chip it is based on. It cannot be a simple port expander like the normal I2C backpacks. The documentation does not mention a "compatibility mode" so that libraries for example of the Arduino LiquidCrystal_I2C.h type can use it unless, that is, the LCD03 mentioned was effectively a standard I2C backpack of the PCF8574 type.

Edit:
And in the meantime, I have found this:
https://andatche.com/code/arduino/lcd03/

and some of the history appears here: https://forum.arduino.cc/index.php?topic=643419.0

Paul__B

I'm curious to know what chip it is based on.
I read it as a PIC18F-something or other.

LukeOliver2001

Sorry I must've missed that part... the chip is a PIC18F23K22

6v6gt

Sorry I must've missed that part... the chip is a PIC18F23K22
I've just looked. It appears to be remarkably well specified with a massive 512KB of RAM if you believe this summary:

https://www.microchip.com/wwwproducts/en/PIC18F23K22

Careful examination of the data sheet tells a different story.

Go Up