Blinking cursor lcd display

Hi everyone. i’m not really experienced in programming so probably i’m doing something wrong here. Basically i’m doing a signal generator with the AD8590 chip and i wanted to set with a keyboard the frequency directly for every number. So the lcd is starting with 10 000 000 Hz shown on the display and i’m trying to create a blinking cursor under the last 0 so with the keyboard if you press up key the result will be 10 000 001 Hz and then if i press left key the cursor goes left by one digit and if i press for example down key it will show something like 10 000 091 Hz. Basically i want to change every digit directly with 4 buttns up, down, left right. My biggest problem is with the cursor. i cannot make it blink and is seems it’s moving fast in every position in the lcd unless i use the delay in loop cycle.

const long interval = 700;
unsigned long previousMillis = 0;
int wait = 0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
}

void loop() {
  unsigned long currentMillis = millis();
  lcd.setCursor(0,0);
  lcd.print("1000000");
  lcd.setCursor(7,0);
  if (currentMillis - previousMillis >= interval) 
  {
    previousMillis = currentMillis;
    
    if(wait == 0)
    {
      lcd.cursor();
      wait = 1;
    }
    else 
    {
      lcd.noCursor();
      wait = 0;
    }
  }
}

i can’t use the delay cause it freeze the arduino so it takes so long to read input keys to change digits. How can i achieve this? thank you so mutch

All this is happening on every loop iteration and probably interferes with your attempts to make the cursor blink:

 lcd.setCursor(0,0);
 lcd.print("1000000");
 lcd.setCursor(7,0);

I suggest for testing, you move those 3 lines into setup() just to see how it reacts.

The other think you could consider is making the entire character blink instead of the cursor. You do this by alternately displaying the character then a blank.

Hey MadEncoder,

In order to make the cursor blink you need to enable your cursor using lcd.cursor() and then call lcd.blink() to make your cursor blink. You are just enabling or disabling the cursor in your example, unless you need to control the blinking speed of the cursor?

As to your fast-moving-cursor issue, you did not supply an example, but I suppose you are just checking if the keypad button went high, and you move the cursor if it is? I would suggest that you detect a press-and-release on your keypad instead of only a press. This will slow down your cursor without the need of a delay.

As 6v6gt noted, you should only write to the display when the text changes. The best way would be to create a method containing the "setCursor-print-setCursor" code piece with the text to print as parameter. Then you can call it once from the setup method, and again in your main loop when the text on the display needs to be changed.