Hello !! I'm kinda playing around with my arduino and i'm attempting to learn how to display stuff on my LCD. I want it to display a certain message when my push button is released, and then another message when i push the button down. I followed the guide for the liquid Crystal and powered up my arduino perfectly. Now i want to get a little tricky with the push button. I set up my push button as a digital input (7). I tried this code but couldn't get it to work. Any suggestions ?!?!
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int pin=7;
int state=0;
void setup() {
Serial.begin(9600);
pinMode(pin,INPUT);
lcd.begin(16,2);
}
void loop() {
state=digitalRead(pin);
if (state=HIGH)
lcd.setCursor(0,0);
lcd.print("I am new to this");
if (state=LOW)
lcd.setCursor(0,1);
lcd.print("hellow");
Serial.println(state);
delay(500);
}
Hey ! I got it to work without using if statements. Here's my new code. I'll try using if statements just to get a hang of both. I'll look into = and ==. Thanks guys !!
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int pin=7;
int state=0;
void setup() {
Serial.begin(9600);
pinMode(pin,INPUT);
lcd.begin(16,2);
}
void loop() {
state=digitalRead(pin);
switch(state) {
case LOW:
lcd.clear(); //clears LCD screen
lcd.setCursor(0,0); // set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.print("Hello !"); // prints text onto assigned cursor position
break; //exit from loop
case HIGH:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("I pushed the");
lcd.setCursor(0,1);
lcd.print("button");
break;
}
Serial.println(state);
delay(500);
}