Go Down

Topic: LCD pulsing text (Read 1 time) previous topic - next topic

gazz

Nope, even with the delays removed, it still takes it's time,

i've changed a few things, got rid of all delays except the one that keeps the 'Belegdruck' text on screen for a short while, then clears the screen, makes no difference if i remove that delay too,

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

int buttonPin1= 6;
int buttonPin2= 7;
int buttonPin3= 8;
int buttonPin4= 9;

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

void setup()
{
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);

  digitalWrite(buttonPin1, LOW);
  digitalWrite(buttonPin2, LOW);
  digitalWrite(buttonPin3, LOW);
  digitalWrite(buttonPin4, LOW);
}


void loop(){
  int buttonState1 = digitalRead(buttonPin1);
  int buttonState2 = digitalRead(buttonPin2);
  int buttonState3 = digitalRead(buttonPin3);
  int buttonState4 = digitalRead(buttonPin4);

  if(buttonState1== HIGH){
    lcd.setCursor(0,0);
    lcd.print("   >>Belegdruck<<   ");
    delay (100);
    lcd.clear();
  }
   
  else if (buttonState2==HIGH){
    lcd.setCursor(0,0);
    lcd.print("Fahrschein Nor  2.70");
  }
  else if(buttonState3== HIGH){
    lcd.setCursor(0,0);
    lcd.print("Kurzstrecke     1.70");
  } 
  else if(buttonState4== HIGH){
    lcd.setCursor(0,0);
    lcd.print("Tageskarte      9.00");
  } 
}



The above code works just like before, i removed all the 'int prevButtonState' bits, as i figured they were not needed, the script i got this info from originally had a message on the screen whenever no buttons were pressed, changing to show which were pressed, then back to no button is pressed displayed.

But basically, if i press button 4, it displays it's text, if i then press button 3, it changes immediately to button 3's text, same if i press button 2 after button 3 or 4, and pressing button 1 does the 'Belegdruck' thing, and clears the display,

However, if i press say button 2, then press button 4, it waits about 4 seconds before changing the text to that of button 4, i.e. i can go down the button numbers instiantly, but going up them gives the delays,

Also, even with the button 1 delay before clearing the lcd set for 100 millis, it takes 4 seconds to clear the display.

Something is causing the delay... i can't believe it's the time it takes the loop part of the script to run??

gazz

i'm an idiot,

it was switch bounce,
i'd found parts of cod on various sites, put them together, not realising that by setting the input pins to LOW wasn't doing anything, hence with my buttons going high to be read, the inputs were floating, and i was effectively sending loads of button press commands,

changed the script on the advise of people at my local hackspace....

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

int buttonPin1= 6;    //sets pins buttons are connected to
int buttonPin2= 7;
int buttonPin3= 8;
int buttonPin4= 9;
int buttonPin5= 13;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //sets pins lcd is connected to, running in 4 bit mode, RW pin tied to gnd

void setup()
{
  pinMode(buttonPin1, INPUT);  //assigns button pins as inputs
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(buttonPin5, INPUT);

  digitalWrite(buttonPin1, HIGH);  //sets internal pulldown resistors
  digitalWrite(buttonPin2, HIGH);
  digitalWrite(buttonPin3, HIGH);
  digitalWrite(buttonPin4, HIGH);
  digitalWrite(buttonPin5, HIGH);

  lcd.begin(20, 1);   //lcd size
  lcd.print("Der Omnibussimulator"); //welcome text
  delay(2000);  //displays for 2 secs
  lcd.clear();  //clears display
}


void loop(){
  int buttonState1 = digitalRead(buttonPin1); 
  int buttonState2 = digitalRead(buttonPin2);
  int buttonState3 = digitalRead(buttonPin3);
  int buttonState4 = digitalRead(buttonPin4);
  int buttonState5 = digitalRead(buttonPin5);


  if (buttonState1== LOW){
    lcd.setCursor(0,0);
    lcd.print("Fahrschein Nor  2.70");  //German for single ticket, stays on the lcd untill another buttons is pressed
  }
  else if(buttonState2== LOW){
    lcd.setCursor(0,0);
    lcd.print("Kurzstrecke     1.70");  //German for short trip ticekt, stays on lcd untill another button is presed
  } 
  else if (buttonState3== LOW){
    lcd.setCursor(0,0);
    lcd.print("Tageskarte      9.00");  //German for day ticket, stays on display untill another button is pressed
  } 
  else if(buttonState4== LOW){  //button pressed
    lcd.setCursor(0,0);  //clears display
    lcd.print("   >>Belegdruck<<   ");  //German for 'printing ticket'
    delay(350);
    lcd.noDisplay();
    delay(250);
    lcd.display();
    delay(350);
    lcd.noDisplay();
    delay(250);
    lcd.display();
    delay(550);
    lcd.clear();
  }
  else if(buttonState5== LOW){
    lcd.clear();
  }
}

And it all works, instant response from the buttons, no delays other than those i put in to flash the 'printing ticket' text,

Now to work out how to integrate the 9x4 button matrix into this script, having about 10 or 11 of the matrix'd buttons displaying text on the lcd, the other buttons are to be ignored by tis part of the script.

Go Up