So, I'm new to the Arduino language and I'm trying to program something I thought would be pretty simple:
If a pin (6) on the Arduino is high, display a short message on the LCD, and if that same pin goes low, turn off the lcd screen. I'm pretty sure the circuit is built correctly, because I have gotten it to work with some simpler codes, but now I'm having a hard time.
I am not getting any errors, but when I compile, the LCD will display some random symbols (?, _, o, and arrows). I've tried a few different versions of the code and sometimes I will get it to display my desired message, but not when it's supposed to (ie, the message will show up even though port 6 (powervalp06) == low). Unfortunately I seem to have deleted or saved over the code that was partially working.
I am receiving the correct display text now, however, it is always being displayed. The lcd is not turning off when pin 6 is low as I would like.
To add to that: The serial command I have set up within the circuit tells me that pin 6 is low (0), but as I mentioned before, the lcd is still displaying the message instead of turning off.
My latest code is below. Can anyone help?
#include <LiquidCrystal.h> //include LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //interface pins
int power = 6; //power switch connected to pin 6
int powervalp06 = 0; //value of pin 6
void setup() {
pinMode(power,INPUT); //sets 6 as input
lcd.begin(16,2);
lcd.clear();
Serial.begin(9600);
}
void loop() {
powervalp06 = digitalRead(power);
Serial.print("powervalp06 = "); // prints a label
Serial.println(powervalp06); // prints a tab
delay(500);
if ((digitalRead(powervalp06) == HIGH)) {
lcd.print("Hello! Press");
lcd.setCursor(0,1);
lcd.print("button to begin.");
lcd.noCursor();
}
else {
lcd.noDisplay ();
}
}