Ok, this is some really basic stuff but I am trying to learn Arduino by pasting together stuff I learned in the different tutorials.
This is what I want Arduino to do.
When I press my button (HIGH) the LCD text should say "Knappen aro nedtryckt!"
If it is not pressed (LOW), it should say "Tryck pa knappen!"
However, right now it displays both messages at the same time, flashing in between the overlaying text. When I do press the button the message I want to display is showing steady (flashing stopped), when I let go the flashing between the two messages start again.
How do I get it to not execute the "if" text line when the button is LOW?
Here is my code.
#include <LiquidCrystal.h>
const int knapp=8;
int buttonState = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(knapp, INPUT);
lcd.begin(16, 2);
}
void loop() {
buttonState = digitalRead(knapp);
if (buttonState == HIGH){ // This is executed even if the button is NOT pressed.
lcd.setCursor(0, 0);
lcd.print("Knappen aro");
lcd.setCursor(0, 1); // Here I changed so the text is displayed on the next row.
lcd.print("nedtryckt!");
}
else {
lcd.setCursor(0, 1);
lcd.print("Tryck pa knappen!");
}
}
Like I said very basic, but I am trying to learn.