Hello,
I am kind of new to Arduino and I am running into an issue with the communication between the Adafruit I2C LCD and an Arduino Pro Mini. Attached is a very simple code which uses a select button to display either "Hello" if the state is High or "Good-Bye" if the state is not High. I am having an issue with the display reading properly when the button is changing state. Sometimes it changes after about 30 seconds and then sometimes it doesn't change. I have checked the voltage when the button changes state and it changes from 5V to 0V and vice-versa so that seems okay. Is this an issue with the speed of I2C communication or is it a programming problem?
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
#define OFF 0x0
#define RED 0x1
#define YELLOW 0x3
#define VIOLET 0x5
int buttonState = 0;
const int button = 7;
void setup()
{
lcd.begin(16, 2);
pinMode(button, INPUT);
lcd.setBacklight(1);
lcd.clear();
Serial.begin(9600);
}
void loop()
{
buttonState = digitalRead(button);
if (buttonState == HIGH)
{
lcd.setCursor(0, 0);
lcd.print("Hello");
Serial.print("Hello");
delay(10);
}
else
{
lcd.setCursor(0, 0);
lcd.print("Good-bye");
Serial.print("Good-Bye");
delay(10);
}
}