Return value is not updated?

Here's the code, thanks! :slight_smile:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11, 6, 5, 4 , 3);

int buttonset = 8; //button set
int buttoncounter =9; //button counter
int buttonmode =10; //button mode

int pushcounter=0; //initiate counter
int pushcounter2 =0; //initiate counter 2
int buttonstate=0; //initiate buttonstate (for counter purpose)
int lastbutton=0; //initiate lasstbutton (for counter purpose)
int modechange=0; //initiate mode change (to toggle from counter one, to counter 2)

int x = 25; //initial value
volatile int y = x; //initial final value

void setup() //setup
{
pinMode(buttonset, INPUT);
pinMode(buttoncounter, INPUT);
pinMode(buttonmode, INPUT);

lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Start!");
lcd.clear();
}

void loop()
{

if (digitalRead(buttonmode) == HIGH && modechange==0) //once the buttonmode is pressed to HIGH and modechange=0
{
counter(); //calling function counter and return value final value = y, calculated in counter function

modechange=modechange+1; //update modechange=1
}

else if (digitalRead(buttonmode) == HIGH && modechange==1) //if the buttonmode is pressed to HIGH
{

counter2(); //calling function counter2 and return final value y, calculated in counter2 function

modechange=0;
}

else //as long as buttonmode is not press to HIGH and mode change is initial=0, the LCD will display the initial y=x=25
{

lcd.setCursor(0,0);
lcd.print("Current value");
lcd.setCursor(0,1);
lcd.print(y); //should display what is initial, and if any changes occur(due to counter or counter2), this value should change

}

}

void counter() //function counter
{
while ( digitalRead(buttonset) == LOW)
{
buttonstate = digitalRead(buttoncounter);
if (buttonstate != lastbutton)
{
if (buttonstate == HIGH)
{
pushcounter++;

lcd.setCursor(0,0);
lcd.print("button pushes:");
lcd.setCursor(0,1);
lcd.print(pushcounter);
y= x +pushcounter;
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(y);
}

else
{
lcd.print("");
}

lastbutton=buttonstate;
}
y=x + pushcounter;
}
}

void counter2() //fucntion counter2
{
while ( digitalRead(buttonset) == LOW)
{
buttonstate = digitalRead(buttoncounter);
if (buttonstate != lastbutton)
{
if (buttonstate == HIGH)
{
pushcounter2++;

lcd.setCursor(0,0);
lcd.print("button pushes:");
lcd.setCursor(0,1);
lcd.print(pushcounter2);
y= x - pushcounter2;
delay(500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(y);
}

else
{
lcd.print("");
}

lastbutton=buttonstate;
}
y=x - pushcounter2;
}
}