Hello, I'm preety new to Arduino programing. I'm creating one of my first projects and I have a problem with a very simple code.
Every 20ms i'm sending pulsed signal to the LED - very easy and it's working as intented. But... After adding an LCD display to the project on which I want to display data in the loop (refreshing every 1 second), interference appears that affects the LED blinking frequency.
Each time the LCD display is being refreshed (LCDRefreshTime), additional LED flash occurs. How to prevent this?
I'm using Arduino Uno R3 and 1602 LCD display ( HD44780). Also i'm using LiquidCrystal library to control the LCD display.
Here is my test code:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
unsigned long LCDTime = 0;
unsigned long LCDSavedTime = 0;
const int LCDRefreshTime = 1000; // 1s refresh time
const int outPin = 9;
void setup() {
lcd.backlight(); // lcd backlight ON i2c
lcd.init(); // initialize the lcd i2c
lcd.home(); // lcd coursor to 0,0
lcd.print("Initializing...");
pinMode(outPin, OUTPUT);
delay(1000);
lcd.clear();
}
void loop() {
TestPulse();
DisplayData();
}
void TestPulse() {
digitalWrite(outPin, LOW);
delay (20);
digitalWrite(outPin, HIGH);
delay (20);
}
void DisplayData () {
LCDTime = millis();
if (LCDTime - LCDSavedTime >= LCDRefreshTime) {
LCDSavedTime = LCDTime;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Line 1: ");
lcd.setCursor(0, 1);
lcd.print("Line 2: ");
}
}