#include <Wire.h>
#include <LiquidCrystal.h>
int temp;
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char Nick[15] = {' ', ' ', 'T', 'A', 'R', 'I', 'F', ' ', 'Z', 'I', 'N', 'E', 'D', ' ', ' '};
int butonPin = 2;
void setup() {
Wire.begin(1);
Serial.begin(9600);
pinMode(butonPin,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(butonPin), Rev, RISING);
lcd.begin(16, 2);
}
void loop() {
Wire.onReceive(data);
lcd.setCursor(2, 1);
lcd.print(temp);
if (temp < 25) {
lcd.setCursor(5, 1);
lcd.print("NORMAL");
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(" ");
}
if (temp >= 25 && temp <= 30) {
lcd.setCursor(5, 1);
lcd.print("HOT");
lcd.print(" ");
lcd.setCursor(11, 1);
for (int i = 0 ; i < 3 ; i++) {
lcd.print(" ");
}
}
if (temp > 30) {
lcd.setCursor(5, 1);
lcd.print("VERY HOT");
lcd.print(" ");
}
lcd.setCursor(0, 0);
for (int j = 15; j > 0 ; j--) {
lcd.print(Nick[j]);
}
lcd.setCursor(0, 0);
delay(70);
int swap = Nick[15];
for (int i = 15; i > 0; i--) {
Nick[i] = Nick[i - 1];
}
Nick[0] = swap;
}
void Rev(){
Wire.onReceive(data);
lcd.setCursor(2, 0);
lcd.print(temp);
if (temp < 25) {
lcd.setCursor(5, 0);
lcd.print("NORMAL");
lcd.print(" ");
lcd.setCursor(12, 0);
lcd.print(" ");
}
if (temp >= 25 && temp <= 30) {
lcd.setCursor(5, 0);
lcd.print("HOT");
lcd.print(" ");
lcd.setCursor(11, 0);
for (int i = 0 ; i < 3 ; i++) {
lcd.print(" ");
}
}
if (temp > 30) {
lcd.setCursor(5, 0);
lcd.print("VERY HOT");
lcd.print(" ");
}
lcd.setCursor(0, 1);
for (int j = 15; j > 0 ; j--) {
lcd.print(Nick[j]);
}
lcd.setCursor(0, 1);
delay(70);
int swap = Nick[15];
for (int i = 15; i > 0; i--) {
Nick[i] = Nick[i - 1];
}
Nick[0] = swap;
}
void data(int numBytes) {
while (Wire.available()) {
temp = Wire.read();
}
}
In lcd's first line i have scrolling text.
Second line it shows current temperature and data from another master device.
My question is i want to change text line when button pressed and text shouldn't go back to old state it need to be stay in changed line and when the button repressed it change again
In my code when the button pressed several times lcd gone weird :
I tried swap lines with lcd.setCursor() function : In loop function :
lcd.setCursor(0, 0);
for (int j = 15; j > 0 ; j--) {
lcd.print(Nick[j]);
}
In reverse function :
lcd.setCursor(0, 1);
for (int j = 15; j > 0 ; j--) {
lcd.print(Nick[j]);
}
Thanks for answers guys
loop()