I'm making a fare meter for our school project. I have too much lcd.print code. This code is not finished yet. My only concern is how to minimize the usage of lcd.print. I think it's the one that makes my sensor reading slow.
I'm new at Arduino; sorry if I have too many mistakes. I appreciate any of your answers. Thank you!
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC(6, 7, 8);
float d[4] = {};
int x = 0;
int f = 0;
int dis = 0;
const uint8_t disBut = 13;
int input = A0;
int state = 0;
int disF = 0;
int buttonstate = 0;
LiquidCrystal_I2C lcd(0x27, 20, 4);
LiquidCrystal_I2C lcd1(0x26, 20, 4);
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd1.init();
lcd1.backlight();
pinMode(disBut, INPUT);
pinMode(buttonstate, OUTPUT);
}
void loop() {
myRTC.setDS1302Time(18, 10, 10, 7, 18, 9, 2020);
Serial.print("Current Date / Time: ");
Serial.print(myRTC.dayofmonth);
Serial.print("/");
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" ");
Serial.print(myRTC.hours);
Serial.print(":");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);
delay(500);
d[0] = (x * 1.73);
d[1] = (x * 1.73);
d[2] = (x * 1.73);
d[3] = (x * 1.73);
lcd.setCursor(8, 0);
lcd.print(d[0]);
lcd.setCursor(8, 1);
lcd.print(d[1]);
lcd.setCursor(8, 2);
lcd.print(d[2]);
lcd.setCursor(8, 3);
lcd.print(d[3]);
lcd.setCursor(0, 0);
lcd.print(F("P1"));
lcd.setCursor(0, 1);
lcd.print(F("P1"));
lcd.setCursor(0, 2);
lcd.print(F("P1"));
lcd.setCursor(0, 3);
lcd.print(F("P1"));
lcd.setCursor(6, 0);
lcd.print(F("D="));
lcd.setCursor(6, 1);
lcd.print(F("D="));
lcd.setCursor(6, 2);
lcd.print(F("D="));
lcd.setCursor(6, 3);
lcd.print(F("D="));
lcd1.setCursor(0, 0);
lcd1.print(F("W="));
lcd1.setCursor(0, 1);
lcd1.print(F("W="));
lcd1.setCursor(0, 2);
lcd1.print(F("W="));
lcd1.setCursor(0, 3);
lcd1.print(F("W="));
lcd1.setCursor(6, 0);
lcd1.print(F("dscnt="));
lcd1.setCursor(6, 1);
lcd1.print(F("dscnt="));
lcd1.setCursor(6, 2);
lcd1.print(F("dscnt="));
lcd1.setCursor(6, 3);
lcd1.print(F("dscnt="));
lcd1.setCursor(15, 0);
lcd1.print(F("F="));
lcd1.setCursor(15, 1);
lcd1.print(F("F="));
lcd1.setCursor(15, 2);
lcd1.print(F("F="));
lcd1.setCursor(15, 3);
lcd1.print(F("F="));
int counter=digitalRead(A0);
if (state == 0) {
switch (counter) {
case 1:
state = 1;
lcd.setCursor(11, 0);
x = x + 1; lcd.print(x);
break;
case 0:
state = 0;
break;
}
}
if (counter == LOW)
state = 0;
if (state == 0) {
switch (counter) {
case 1:
state = 1;
x = x + 1;
break;
case 0:
state = 0;
break;
}
}
if (counter == LOW)
state = 0;
}