Need help how to use sub function in switch case statement ?

I want my program to work like when you select one item then they ask you to press button to confirm. My project is vending machine , I have 3 items to choose. Then first when select the 3rd items I want it to ask you for confirmation the when you press button to confirm. It ask to recheck (need to confirm again) after that the rest of the sequence work.

case 3:
        if (digitalRead(pressing == 1)) {
          lcd.clear();
          lcd.setCursor(0, 0);
          Serial.println("EMERGENCY ONLY");
          lcd.setCursor(0, 1);
          Serial.println("CONFIRM ?");
          Serial.println("MASSAGE ALERT CONFIRM 1 PRESS BUTTON");
          if (digitalRead(pressing == 2)) {
            lcd.clear();
            lcd.setCursor(0, 0);
            Serial.println("ARE YOU SURE ?");
            lcd.setCursor(0, 1);
            Serial.println("CONFIRM ?");
            Serial.println("MASSAGE ALERT CONFIRM 2 PRESS BUTTON");
            if (digitalRead(pressing == 3)) {
              servo3.writeMicroseconds(2000); //Rotate CW
              delay(960);
              servo3.writeMicroseconds(1500); //Stop
              lcd.clear();
              lcd.setCursor(0, 0);
              lcd.print("Status : Item 3");
              lcd.setCursor(0, 1);
              lcd.print("is delivered");
              delay(3000);
              Serial.println("CHECK3");
              delay(5000);
            } else; {
              break;
            }
          } else; {
            break;
          }

(I have 3 switch which 3 of them for selection items.)

if (digitalRead(pressing == 1))

Oops

if (digitalRead(pressing == 2))

And again.

(And another for, you guessed it, == 3)

else; Also, oops

You need to post your entire sketch. Because you have issues with your conditional statements (as pointed out already) it is difficult to tell what you want the code to actually do.

            } else; {
              break;
            }
          } else; {
            break;
          }

awkward. there not need for an unused else.
the ";" following the else is the else statement.
the braces do nothing.

the above code can be replaced by a single "}"

looks like you question is unrelated to the title of the thread ???

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.