Problem with nested ifs and notifications

Hello, I’m working on an app controlled lock. My code prompts users to enter in their name, and if it is one of the accepted names (Rita or Michelle), the buttons and labels that are blacked out become visible. The nested if-else statements are supposed to send out a notification saying which user did a button push, but for some reason it won’t run. Any help would be appreciated! Here is the relevant part of the code:

Note: The only notification that works is the “Michelle” and “Rita” when first entering the name into the terminal.

int lockCountMichelle = 0;
int lockCountRita = 0;

 BLYNK_WRITE(V1) {
 
doorState = digitalRead(V25);
appButtonState = digitalRead(V26); 

    if (String("michelle") == param.asStr()) {
      terminal.println(" ");
        terminal.println("Welcome Michelle!");
        if (doorState == LOW) {
        Blynk.virtualWrite(door_state, "Open");   
        Blynk.setProperty(V25, "color", "#FF0000"); // Red                            
        Blynk.setProperty(V26, "offLabel", "Lock");
        Blynk.setProperty(V26, "color", "#FF0000"); // Red
        Blynk.setProperty(V26, "onLabel", "Unlock");
        }
            if (appButtonState == LOW) {
                    Blynk.virtualWrite(V25, "Close");                               
                    Blynk.setProperty(V26, "offLabel", "Lock");  
                    
            } else if (appButtonState == HIGH) {
                    lockCountMichelle++;     
                    Blynk.notify("Michelle"); 
          
      if (lockCountMichelle > 1 and appButtonState == HIGH) {
                    lock();
                    Blynk.notify ("Michelle has locked the door!");  
                    
     } else if (lockCountMichelle >2 and appButtonState == HIGH) {
                    unlock();
                    Blynk.notify ("Michelle has unlocked the door!");
                    lockCountMichelle = 0;  
       
     }
      }
    } else if (String("rita") == param.asStr()) {
        terminal.println(" ");
        terminal.println("Welcome Rita!"); 
        Blynk.virtualWrite(door_state, "Open");  
        Blynk.setProperty(V25, "color", "#FF0000"); // Red                             
        Blynk.setProperty(V26, "offLabel", "Lock");
        Blynk.setProperty(V26, "color", "#FF0000"); // Red
        Blynk.setProperty(V26, "onLabel", "Unlock"); 

         if (appButtonState == LOW) {
                    Blynk.virtualWrite(door_state, "Close");                               
                    Blynk.setProperty(V26, "offLabel", "Lock");  
            } else if (appButtonState == HIGH) {
                    lockCountRita++;      
                    Blynk.notify("Rita"); 
            
       if (lockCountRita > 2 and appButtonState == LOW) {
                    lock();
                    Blynk.notify ("Rita has locked the door!");    
     } else if (lockCountRita >3 and appButtonState == HIGH) {
                    unlock();
                    Blynk.notify ("Rita has unlocked the door!");
                    lockCountRita = 0;  
     } 
     }

Looks very messy. Tidy it up and test with just one user until you have ironed out your bugs.
If you don’t know what’s happening sprinkle your code with Serial.println().

1 Like

It may be a better choice to use the switch/case statement here instead of all those nested if’s. (See arduino.cc for syntaxis).