So I am trying to use one input to control an LCD display. The goal being that once one of the buttons is pressed it delivers a message. I have watched quite a few tutorials and can get the program to work sometimes. Yet, it is still pretty buggy and I am wondering why that is. To get this make this project work somewhat used this code.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buttonPin = A0; //Button and LED pin numbers
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
//lcd.print("hello, world!");
Serial.begin(9600); //Serial monitor used to determine limit values
}
void loop()
{
int temp = analogRead(buttonPin); //Read the analogue input
Serial.println(temp); //Display the read value in the Serial monitor
if (temp = 340) //Lower limit for first button - if below this limit then no button is pushed and LEDs are turned off
{
lcd.print("No Button Pushed \n");
}
else if (temp = 867) //First button limit - if below this limit but above previous limit then the first button is pressed
{
lcd.print("Button 1 Pushed");
}
else if (temp = 156 ) //Second button limit
{
lcd.print("Button 2 Pushed");
}
else //If none of the previous buttons are pressed, then the third button must be pressed
{
lcd.print("Button 3 Pushed");
}
delay(100); //Delay for stability
}
The output sometimes is correct other times it is off. I think it has something to do with the circuit. Yet, I am scratching my head to find out what.
