I'm trying to put together bits of code to eventually end up with a 9x4 matrix of button inputs, send each individual button pressed as a HID usb gamepad, whilst certian buttons display text on a lcd.
I have got the lcd working, running it in 4 bit mode, it's a 20 x 1 character module... which is from the bus ticket machine i am interfacing to a computer simulator,
So now i am looking having button presses display different text on the lcd, eventually it will need to scan the matrix'd buttons, and display text for about 10 different buttons being pressed,
Text to display will be ticket type, to stay on the display untill either the cancel button is pressed, or the print ticket button is pressed, when the display is to change to show 'printing' for 2 seconds, then blank the display.
This is my script so far... a combination of the standard lcd library, and a bit of script i found from someone who wanted 3 buttons to display text,
// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int switchPin = 10; // switch is connected to pin 10
int switchPin1 = 9; // switch is connected to pin 9
int switchPin2 = 8; // switch is connected to pin 8
int prevState; // variable for reading the pin status
int currState; // variable to hold the last button state
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(20, 1);
pinMode(switchPin, INPUT); // Set the switch pin as input
pinMode(switchPin1, INPUT); // Set the switch pin as input
pinMode(switchPin2, INPUT); // Set the switch pin as input
}
void loop(){
currState = digitalRead(switchPin);
if(currState !=prevState){
if(currState == LOW){
lcd.println(" ");
lcd.clear();
}
else {
prevState = currState;
currState = digitalRead(switchPin);
if(currState !=prevState)
lcd.print(0, 0);
lcd.print("Fahrschein Erm 1.70");
}
}
prevState = currState;
currState = digitalRead(switchPin1);
if(currState !=prevState){
if(currState == LOW){
lcd.println(" ");
lcd.clear();
}
else {
prevState = currState;
currState = digitalRead(switchPin1);
if(currState !=prevState)
lcd.print(0, 0);
lcd.print("TagesKarte 9.00");
}
}
prevState = currState;
currState = digitalRead(switchPin2);
if(currState !=prevState){
if(currState == LOW){
lcd.println(" ");
lcd.clear();
}
else {
prevState = currState;
currState = digitalRead(switchPin2);
if(currState !=prevState)
lcd.print(0, 0);
lcd.print("Fahrschein Nor 2.70");
}
}
prevState = currState;
}
It works, however the text is pulsing when it is shown, not flashing, but pulsing from bottom to top, as if it's being refreshed at too slow a rate,
or it might be because of the code that is keeping a look out for button presses?
I also see no way to alter how long the text stays displayed for, ATM it displays for about 4 or 5 seconds, then blanks, and there is a delay if you press another button before it changes the text.
Is there a better way to do what i am trying, and will this even be compatable with matrix buttons when i try and add that part of the code?