Can i pick the collectives brains once more :)
i have the lcd text responding instantly to the buttons, and untill my
matrix keypads arrive in the post (maplins sell the 3x4 ones for �2.99, but
have discontinued them, however they had over 40 at head office, so i got a
couple on order) i'd like to make it so the print ticket button only
displays it's text after a ticket selection button has been pressed.
my script is now:
#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();
}
}
So i want button 4 to only respond after either button 1, 2 or 3 have been
pressed,
button 5 is the cancel button btw,
i think i need to change one of the 'else if' commands, but need to be able
to still use the cancel button or select another ticket button,