UKHeliBob:
if (currentLCDMillis - previousLCDMillis > interval2)Which of the two different variables named previousLCDMillis is this checking ?
The global one or the local one ?
Local one. Serial.println(currentLCDMillis - previousLCDMillis); shows values 0-2000ish and reseting.
Thanks PaulS, now it works.
#include <Wire.h>
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(32, 30, 28, 26, 24, 22);
//LiquidCrystal lcd_name(rs, en, d4, d5, d6, d7);
int previousLCDMillis = 0; //set first old time to 0
void setup() {
//My LCD was 16x2
lcd.begin (16, 2);
lcd.home(); // go home
Serial.begin(9600);
}
void loop() {
//bunch of other stuff here
kalba();
}
void kalba() {
//function telling users they should select the language
//four languages should switch between with the delay of 2 sec.
unsigned long currentLCDMillis = millis(); //check current time
unsigned long interval2 = 2000;
static unsigned long previousLCDMillis = 0; //set first old time to 0
String languages[4] = {"Kalba?", "Language?", "Runa?", "Y3Ik?"};
static int langCycle = 0; //cycle is 0, it is used and waits for millis to hit 2000
if (currentLCDMillis - previousLCDMillis > interval2) {
langCycle++;
lcd.setCursor (6, 0);
lcd.print(" "); //delete the old text - DOES NOT WORK
previousLCDMillis = currentLCDMillis;
}
lcd.setCursor (6, 0);
lcd.print(languages[langCycle]);
// Serial.println(langCycle);
// Serial.println(currentLCDMillis - previousLCDMillis);
if (langCycle == 4) {
langCycle = 0;
}
}