Trouble with if statement

int sendkey = 5;
int trigger=12;
int buttonState = 0;
int buttonsendstate =0;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(sendkey, OUTPUT);  
  pinMode(trigger, INPUT);   
  digitalWrite(sendkey, HIGH);
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
buttonState = digitalRead(trigger);
buttonsendstate = digitalRead(sendkey);
Serial.print(buttonState);
 Serial.print(",");
  Serial.println(buttonsendstate);
  

if (trigger==HIGH){
 
  digitalWrite(sendkey, LOW);
  delay(1000);               // wait for a second
 // digitalWrite(sendkey, LOW);

  
 }//end if
   else {delay(10);}

  
}

So I am using this code to trigger a traverse to move from a button input. I set pin 12 as HIGH when I connect it to 5V and I read the serial where it shows a change from 0 to 1, but it does not change the sendkey value from 1 to 0. It is like it is just skipping over the if statement. I have verified that it is not changing the value over to 0/LOW from the serial and that when it is low the traverse moves.
Any help?

Okay I figured it out I have to call the digital read variable not the pin itself.

“if (buttonState==HIGH){”

You test if (trigger==HIGH)

trigger is 12, HIGH is true, aka 1.

12 is not equal to 1. So that if condition is never true.

I think you meant (digitalRead(trigger)==HIGH) there.

Also, did you remember the pulldown resistor on pin 12? Without it, when the button isn't pressed, the pin will be connected to nothing, and will "float" - that is, it will pick up noise from the environment and read a random value. A resistor (anywhere from 1k to 100k is fine, 10k is the usual default) between that pin and ground ensures that it will read LOW when the button connecting it to 5v is not pressed.

Even better, you wire the switch to connect the pin to ground, and set the pinmode of the pin to INPUT_PULLUP - this enables the internal pullup, so no external resistor is needed (there's no internal pulldown though) - and then invert the logic, ie if (digitalRead(trigger)==LOW)

Finally, you can make your code easier for everyone (including you) to read by pressing ctrl+T to fix the indenting.

In the future, be sure to post questions in the correct section - this section is for troubleshooting the IDE or hardware, not questions about programming or your project.