void doorLockFunction(){
while (1) {
doorstatus = digitalRead(PIN_BUTTON);
if (doorstatus == LOW) {
Serial.print("Door Lock Status :");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
break;
}
}
}
I need alternative solution
instance while loop ..Any other event / function are there .. ?
Here as a public service is the OP's code control-T'd and code tagged.
I suggested to the mods that it get moved: this is surely the wrong board (edit; I see it's been moved)
const int PIN_BUTTON = 10;
int doorstatus = HIGH; // Door status, default High status
void setup()
{
pinMode(10, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
}
void loop()
{
doorLockFunction();
}
void doorLockFunction()
{
while (1)
{
doorstatus = digitalRead(PIN_BUTTON);
if (doorstatus == LOW)
{
Serial.print("Door Lock Status :");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
break;
}
}
}
If you do not want the program to wait in the function and block other code execution then you cannot use a while. Why not use an if instead and call the function each time through loop() when you need to check the status of the door ?
As AWOL suggest, a state machine sounds like it fits the bill