Boolean function in while loop

Hello everyone! i have a problem. i am totally confused. When i make this only function in a new file, it’s totally working. but when i try to put the exact same function together with some other function, it doesn’t working. Can anyone solve my problem or tell me where did i do wrong ?
Thanks in advanced.
P/s : I only post a snippet of my coding because the whole coding is quite long

#include "MapFloat.h"
#include <Keypad.h>

const int LED_ERROR = 10;
const int LED_REFRIGERACION = A4;
const int LED_MOTOR1 = A2;
const int LED_MOTOR2 = A3;
const int LED_CAMBIOS = 12;
const int BUTTON_CAIDA = 11;
const int BUTTON_IMPORTE = A5;
const int UPS = A0;
const int SENSOR_TEMPERATURA = A1;

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the kpd

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

String refrescos[]  = {"A35", "A36", "A37", "A38", "A39", "A40"};
String input_codigo;
unsigned long previousMillis = 0;
float importe = 0.00;
float precio;
String refresco;
int state;



void setup() {
  // put your setup code here, to run once:
  pinMode(LED_ERROR, OUTPUT);
  pinMode(LED_REFRIGERACION, OUTPUT);
  pinMode(LED_MOTOR1, OUTPUT);
  pinMode(LED_MOTOR2, OUTPUT);
  pinMode(LED_CAMBIOS, OUTPUT);
  pinMode(BUTTON_CAIDA, INPUT_PULLUP);
  pinMode(BUTTON_IMPORTE, INPUT_PULLUP);
  pinMode(UPS, INPUT);
  pinMode(SENSOR_TEMPERATURA, INPUT);
  Serial.begin(9600);
  input_codigo.reserve(32);
}

.
.
.
.
.
.
.
if (state == 5) { // detectar la caida del producto
    static unsigned long previousMillis;
    previousMillis = millis();
    do {
      Serial.println("previous millis");
      Serial.println(previousMillis);
      Serial.println("current millis");
      Serial.println(millis());
     // bool caye = caidaProducto();
      if (caidaProducto()) {
        Serial.println("el producto se ha caido ... ");
        state = 6;
      }
      else {
        Serial.println("volver a dispensar el producto... ");
        state = 4;
      }
    }
    while ((millis() - previousMillis < 10000) && !caidaProducto());
    Serial.println("sale de while");

  }

.
.
.
.
.
.
//deteccion de la caida producto
bool caidaProducto() {
  int lastState = LOW;  // the previous state from the input pin
  int currentState;     // the current reading from the input pin
  unsigned long pressedTime  = 0;
  bool isPressing = false;
  bool estaCayendo = false;

  currentState = digitalRead(BUTTON_CAIDA);
  if (lastState == HIGH && currentState == LOW) {       // button is pressed
    pressedTime = millis(); //Save the instants when the button is pressed
    isPressing = true;
    estaCayendo = false;
  } else if (lastState == LOW && currentState == HIGH) { // button is released
    isPressing = false;
  }

  if (isPressing == true && estaCayendo == false) { // if button is pressed
    long pressDuration = millis() - pressedTime; // calculate the time when the button is pressed

    if ( pressDuration > 5000 ) {
      Serial.println("El producto se ha caido");
      estaCayendo = true;
    }
  }
  lastState = currentState;  // save the the last state
  return estaCayendo;
}

3 posts were merged into an existing topic: Reset a boolean function