Tactile switch to act like a momentary switch

What I want is something that I think a lot of people use, but I can't find any information on. When I pres a tactile switch I want it to act like it's being held down. Example:

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int potpin = A0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 

int knobbutton = 22; // pin that the tactile switch used to activate the knob control
int knobbuttonval;
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  knobbuttonval = digitalRead (knobbutton);
  
  if (knobbuttonval gets pressed once)
  
  {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 
  }

}

So I basically just don't know what to put in the brackets for the "if" statement. Excuse me if I used incorrect terms, I'm rather new to this.

Thanks

Not sure what you mean by "acts like its being held down" or "gets pressed once"...

What is wrong with "knobbuttonval == HIGH" ?

I thought a tactile switch and momentary switch were more or less the same thing, (I may be wrong, I usually am)

There is this tutorial from Arduino 101 for something similar in effect, but pay more attention to paulRB.

If I understood you correctly, you have a momentary tactile switch and you want it to behave like a latching switch. You can do that by using the technique demonstrated in the state change detection example sketch to detect when a button press occurs and toggle the state of a variable - the variable then holds your latching state.

I thought a tactile switch and momentary switch were more or less the same thing, (I may be wrong, I usually am)

You are right, they are exactly the same thing with the only difference I know of being the tactile feedback, ie they "click" when pressed.

As has been mentioned, detect the button press and change the state of a variable eg

if (buttonPressed()) // write a func that detects a button press and debounces the button
buttonState = !buttonState;


Rob