im getting my self a little confused.
ive got an lcd screen and a few buttons, i want the lcd to display something different depending on the button pressed. i know how to write to the lcd and how to use the clear function to wipe it.
this is what my code currently looks like.
/*
* Mathew Buer - 18/05/2015 @ 12:00
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
// this constant won't change:
const int buttonPin = 7; // the pin that the pushbutton is attached to
const int ledPin = 8; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
// tell the lcd where were startubg
lcd.begin(16, 2);
// set the line of the lcd we wish to print to
lcd.setCursor(0,0);
// message were going to print.
lcd.print(" Lessage Line 1");
// set the lcd to line 2
lcd.setCursor(0,1);
// set the message
lcd.print("Message Line 2");
// delay for showing the message
delay(5000);
lcd.clear();
// initialize the button pin as a input:
pinMode(buttonPin, INPUT_PULLUP);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 2 == 0) {
// set the line of the lcd we wish to print to
lcd.clear();
lcd.setCursor(0,0);
// message were going to print.
lcd.print("BUTTON PRESSED");
}
else
lcd.clear();
lcd.print("TEST");
}
how in order to use button2 to print "Hello World" woudli need to set new varibles for the button state ? ie
int buttonPushCounter2 = 0; // counter for the number of button presses
int buttonState2 = 0; // current state of the button
int lastButtonState2 = 0; // previous state of the button
or is there an eaiser way as this just seems long winded.
Regards