I am using a 16x2 RGB LCD across 2 breadboards and linked to my Adruino Uno R3 with the Vin, GND, Reset, A4 & A5 pins (power and i2c).
I am using the Adafruit kit # 716/714/772 (I know this is not the Adafruit forums but I don't believe the issue is with the display at all; hence, why I am here).
In a very basic description, here is my connections and code:
CONNECTIONS:
Vin --> Power Bus
GND --> Ground Bus
Pin 7 --> Input from tactile pushbutton switch
CODE:
const int button = 7;
int val = 0;
int old_val = 0;
int state = 0;
void setup() {
lcd.begin(16,2);
pinMode(button, INPUT);
}
void loop() {
val = digitalRead(button);
if((val == HIGH) && (old_val == LOW)) {
state = 1 - state;
delay(10);
}
old_val = val;
if(state == 0) {
function_x();
}
if(state == 1) {
function_y();
}
}
void function_x() {
lcd.print("Output1");
}
void function_y() {
lcd.print("Output2");
}
When I upload the code to the Arduino everything is fine. The only issue I have is that the text on the display is flashing incredibly fast and it makes it look washed out. Before you think that it's a bad/cheap/broken LCD, when I do a "lcd.print("");" in the setup() method, there is no washing out/flashing.
I feel like the issue is that the loop function is constantly sampling the value of "state" and each time it is sampled, it traverses the conditional "if" statements and follows through with the directions therein. Its really wasteful on resources and it makes the display look horrid. I thought that I could mitigate that by creating separate methods but the state needs to be read from and reading follows a sampling rate.
Any ideas as to why it is doing this and how better I can align my code to render it easier onto an LCD display?
Thank you in advance.