count numbers

Hello. I have a problem in my code in lcd screen and I want your help.So, I want to count numbers from 0 to 5 with 1 second delay and when the number is 5 ,I want to countdown from 4 to 0 again ,but in the following code the number goes to 4 and then sticks to 4…

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long prevMillis = 0;
const long diasthma = 1000;
int count_up = 0;
int count_down = 0;

void setup()
{
lcd.begin(16, 2);
}

void lcd_timer_up()
{
unsigned long currentMillis = millis();

if (currentMillis - prevMillis >= diasthma)
{
lcd.setCursor(7, 1);
lcd.print(count_up);
if (count_up == 5)
{
count_down = count_up;
lcd_timer_down();
}
else
{
count_up++;
prevMillis = currentMillis;
}
}
}
void lcd_timer_down()
{
unsigned long currentMillis = millis();

if (currentMillis - prevMillis >= diasthma)
{
lcd.setCursor(7, 1);
count_down–;
lcd.print(count_down);
prevMillis = currentMillis;
}
}

void loop()
{
lcd_timer_up();
}

Since void lcd_timer_up() calls void lcd_timer_down() you are running into a problem with the first function counting up and the other function immediately counting down.

You will have to correct the above.

Ugly fix using a flag add to your code.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
unsigned long prevMillis = 0;
const long diasthma = 1000;
int count_up = 0;
int count_down = 0;

byte flag = 0;

void setup()
{

  lcd.begin(16, 2);
}


void lcd_timer_up()
{
  unsigned long currentMillis = millis();

  if (flag == 0 && currentMillis - prevMillis >= diasthma)
  {
    lcd.setCursor(7, 1);
    lcd.print(count_up);

    if (count_up == 5)
    {
      count_down = count_up;
      prevMillis = currentMillis;
      flag = 1;
      count_down = 4;
    }
    else
    {
      count_up++;
      prevMillis = currentMillis;
    }
  }
}
void lcd_timer_down()
{
  unsigned long currentMillis = millis();

  if (flag == 1 && currentMillis - prevMillis >= diasthma)
  {
    lcd.setCursor(7, 1);
    lcd.print(count_down);

    prevMillis = currentMillis;
    count_down--;
    if (count_down < 0)
    {
      flag = 2;
    }
  }
}

void loop()
{
    lcd_timer_up();
    lcd_timer_down();

}
//...
byte wackyCount[] = {0, 1, 2, 3, 4, 5, 4, 3, 2, 1};
byte wackyIndex;
// ...
byte countUpAndDown() {
byte x = wackyCount[wackyIndex];
if (wackyIndex >= 9) wackyIndex = 0;
else wackyIndex++;
return x;
}
//...