Help with function declaration

Hello! i’am working with a program to turn off and on a led, but just with one button.
This program is intended to work for 2 diferent leds that arent related, so i was panning
to use a function with the program i already did and works.
the problem is that the variables arent being recorded, and for the program to work
i need to keep specialy the one named Valant, or as its new name will be after using the program
Valantven.

Hope you can help me, the program is the next one:
</
int pininven=3;
int pinoutven=10;
int estadoven=LOW;
int valantven;
int lecturaven=LOW;

int PBBT (int pinin, int pinout, int estado, int valant, int lectura){
lectura = digitalRead(pinin);

if ((lectura != LOW)){

estado=HIGH;

delay (1000);
}

if (estado == HIGH && valant == LOW) {
valant=HIGH;
Serial.println(valant);
estado=LOW;
}

if (estado == HIGH && valant == HIGH){
digitalWrite(pinout, LOW);
valant=LOW;
Serial.println(valant);
estado=LOW;
delay (600);
}
return valant;
}

void setup() {
pinMode(pininven, INPUT);
pinMode(pinoutven,OUTPUT);
Serial.begin(9600);
}

void loop() {
PBBT (pininven, pinoutven, estadoven, valantven, lecturaven);
Serial.println(valantven);
}
/>

If you place a "&" in front of the argument name, it will works as input and output:

int PBBT (int pinin, int pinout, int estado, int &valant, int lectura) {
 valant = 123;
 return 321;
}

int v, r;
r = PBBT(1, 2, 3, v, 0);

//r is now 321
//v is now 123

Oh my god, that worked so well, thanks very much!
such a little detail that not knowing destroyed the programming XD
thank you very much, have a nice day.

Easy fix! :slight_smile: You could also make it a pointer which allows you to omit the value:

int test(int *value) {
  if (value) *value = 123;
  return 321;
}

int r, v = 0;

r = test(NULL);
//r = 321, v not used

r = test(&v);
//r = 321, v = 123