Got a LCD shield with 5 buttons on it all buttons go onto one wire each one has a different value resister so that the current of the wire can be checked and know with button was pressed
I've noted down the values that you get when each button is pressed and used if loops to print out which button was pressed but for some reason if prints 337 when the serial.println() is at he end of the void loop and prints 298 when the serial.println() is at the beginning of the void loop
// include the library code:
#include <LiquidCrystal.h>
// with the arduino pin number it is connected to
int Value = 0;
int button = "";
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("hello ");
Serial.begin(9600);
}
void loop() {
//sets value as the value from A3
Serial.println(button);
Value = analogRead(A3);
if (88 < Value < 96){
button = "BACK";
}
else if (311 < Value < 325){
button = "MENUE";
}
else if (174 < Value < 182){
button = "DOWN";
}
else if (684 < Value < 691){
button = "UP";
}
else{
button = " ";
}
Serial.println(button);
Serial.println(Value );
delay(1000);
}
// include the library code:
#include <LiquidCrystal.h>
// with the arduino pin number it is connected to
int Value = 0;
int button = "";
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.print("hello ");
Serial.begin(9600);
}
void loop() {
//sets value as the value from A3
Serial.print(button);
Value = analogRead(A3);
Serial.print(F(" "));
Serial.println(Value);
switch (Value)
{
case 88 ... 96:
Serial.println(F("BACK"));
break;
case 311 ... 325:
Serial.println(F("MENUE"));
break;
case 174 ... 182:
Serial.println(F("DOWN"));
break;
case 684 ... 691:
Serial.println(F("UP"));
break;
default:
Serial.println(F("-----"));
break;
}
/*
}
if (88 < Value < 96) {
button = "BACK";
}
else if (311 < Value < 325) {
button = "MENUE";
}
else if (174 < Value < 182) {
button = "DOWN";
}
else if (684 < Value < 691) {
button = "UP";
}
else {
button = " ";
}
Serial.println(button);
Serial.println(Value );
*/
delay(1000);
}